zoukankan      html  css  js  c++  java
  • ggplot2 demo

    title <- rep("A Really Rather Long Text Label", 25)
    value <- runif(25, 1,10)
    spacing <- seq(1:25)
    df <- data.frame(title, value, spacing, stringsAsFactors = FALSE)

    myplot <- ggplot(data=df, aes(x=spacing, y=value, label = title)) +
        geom_text(aes(colour = value),
            size = 2.5, fontface = "bold",
            vjust = 0,
            position = position_jitter(width=5, height=0)) +
        theme_bw() +
        scale_x_continuous(limits = c(-5, 30))+
        scale_colour_gradient(low = "#6BAED6", high = "#08306B") +
        opts(axis.title.x = theme_blank(),
            axis.ticks = theme_blank(),
            axis.text.x = theme_blank(),
            legend.position = "none")
    myplot

     ================================

    library("ggplot2")
    tmp <- data.frame(x=-5:5, y=rnorm(11), lab=LETTERS[1:11])
    p <- ggplot(aes(x=x, y=y, label=lab), data=tmp)+
         geom_point()+
         geom_text(data=subset(tmp, x >0), hjust=-0.5)+
         geom_text(data=subset(tmp, x <=0), hjust=1.5)
    print(p)


    ================================
    dat <- read.table(text="
    cars    trucks  suvs
    1   2   4
    3   5   4
    6   4   6
    4   5   6
    9   12  16", header=TRUE,as.is=TRUE)
    dat$day <- factor(c("Mo","Tu","We","Th","Fr"), 
                 levels=c("Mo","Tu","We","Th","Fr"))
    
    library(reshape2)
    library(ggplot2)
    
    mdat <- melt(dat, id.vars="day")
    head(mdat)
    ggplot(mdat, aes(variable, value, fill=day))+ 
      geom_bar(stat="identity", position="dodge")
    ================================

    http://sape.inf.usi.ch/quick-reference/ggplot2/colour
    ================================

    http://docs.ggplot2.org/current/
  • 相关阅读:
    Idea14 生成webservices
    第10组 Beta冲刺(4/4)
    2019 SDN上机第7次作业
    第10组 Beta冲刺(3/4)
    第10组 Beta冲刺(2/4)
    第10组 Beta冲刺(1/4)
    2019 SDN上机第6次作业
    SDN课程阅读作业(2)
    2019 SDN上机第5次作业
    第10组 Alpha冲刺(4/4)
  • 原文地址:https://www.cnblogs.com/emanlee/p/3521900.html
Copyright © 2011-2022 走看看