Barplot 作图代码

作者: 正踪大米饭儿 | 来源:发表于2017-11-14 09:38 被阅读23次
    image.png

    ggplot2 barplot 分面图代码如下:

    library(ggplot2)
    Data <- read.table("data.txt",header = TRUE)
    Data <- as.data.frame(Data)
    attach(Data)
    Data$Time <- factor(Time,order=TRUE,levels=c("Early","Mid","Late")) 
    
    ## Temperature
     p<-ggplot(data=Data, aes(x=Month, y=Temperature,fill = Time)) + 
      geom_bar(stat="identity", position = position_dodge(width = 0.6),width = 0.5) +
      geom_text(aes(label=Temperature), position = position_dodge(width=0.6), vjust=-0.3) + 
      facet_grid(Year ~ .) + scale_y_continuous(limits = c(0,max(Temperature)))
    
    p <- p + ggtitle(label = "Temperature changes") + theme_light()
    

    数据源(data.txt):

    Year    Month   Time    Temperature Rainfall    Light
    2017    6   Early   23.6    19.9    66.1 
    2017    6   Mid 26.9    22.7    89.2 
    2017    6   Late    26.8    21.2    85.5 
    2017    7   Early   29.7    4.1     82.7 
    2017    7   Mid 29.2    73.1    72.0 
    2017    7   Late    25.8    28.3    32.6 
    2017    8   Early   28.8    7.3     88.9 
    2017    8   Mid 26.9    7.7     64.2 
    2017    8   Late    23.9    13.0    38.6 
    2017    9   Early   23.1    9.4     38.8 
    2017    9   Mid 23.6    6.7     88.0 
    2017    9   Late    22.4    9.3     50.2 
    over    6   Early   24.97   11.08   111.76 
    over    6   Mid 27.09   22.70   107.02 
    over    6   Late    27.03   14.45   88.83 
    over    7   Early   27.44   46.23   58.67 
    over    7   Mid 26.45   55.59   51.99 
    over    7   Late    27.84   48.73   74.16 
    over    8   Early   26.38   43.68   46.28 
    over    8   Mid 26.20   37.09   55.60 
    over    8   Late    24.08   17.38   70.74 
    over    9   Early   22.07   31.39   43.31 
    over    9   Mid 20.56   33.70   50.70 
    over    9   Late    19.49   5.20    48.54 
    

    相关文章

      网友评论

        本文标题:Barplot 作图代码

        本文链接:https://www.haomeiwen.com/subject/ltdxvxtx.html