在x轴ggplot2 r上标记最小值和最大值

时间:2016-10-25 11:25:02

标签: r date ggplot2 label

以下是我的csv文件的一部分:

Date    Site    Al
07/10/2014  Bo6 152.1
07/10/2014  Bo1 157.3
07/10/2014  Bo3 207.1
07/10/2014  Bo4 184.3
07/10/2014  Bo5 23.2
14/10/2014  Bo6 96.8
14/10/2014  Bo1 123.2
14/10/2014  Bo3 124.7
14/10/2014  Bo5 155.6
14/10/2014  Bo4 177.1
28/10/2014  Bo4 239.6
28/10/2014  Bo5 50.3
28/10/2014  Bo6 73.3
31/10/2014  B1  97.2
31/10/2014  D1  79.2
04/11/2014  Bo1 111.1
04/11/2014  Bo3 114.9
04/11/2014  Bo4 235.1
04/11/2014  Bo5 81.8
04/11/2014  Bo6 64.3

直到2015年12月。

这是我使用的代码:

rm(list=ls())
require(ggplot2)
require(reshape2)
require(magrittr)
require(dplyr)
require(tidyr)
require(cowplot)
require(grid)
require(scales)
setwd("~/Documents/Results")
mydata <- read.csv("Metals sheet R.csv")
L <- subset(mydata, Site =="Bo1"| Site == "Bo2"| Site == "Bo3"| Site == "Bo4"| Site == "Bo5" | Site == "Bo6", select = c(Site,Date,Al))
L$Date <- as.Date(L$Date, "%d/%m/%Y")
I <- ggplot(data=L, aes(x=Date, y=Al, colour=Site)) +
  geom_point() + 
  labs(title = "Total aluminium in the Bowydd
       2014-2015.", x = "Month 2014/2015",
       y = "Log of total concentration (mg/L)") +
  scale_x_date(date_breaks = "1 month", date_labels = "%m") + theme_get()
r2 <- I + geom_hline(aes(yintercept= 10, linetype = "NRW limit"), colour= 'red') +
  geom_hline(aes(yintercept= 75.5, linetype = "Geochemical 
  atlas limit"), colour= 'blue') +
  scale_linetype_manual(name = "Limit", values = c(2, 2), 
                        guide = guide_legend(override.aes = list(color = c("blue", "red"))))
r3<- r2 + coord_trans(y = "log10") + annotation_logticks(scaled = FALSE)
r4<-r3 + scale_y_continuous(breaks = c(0,10,100, 500, 1000, 2000, 3000), labels = c(0,10,100, 500, 1000, 2000, 3000))
ggdraw(r4) + draw_figure_label(label = "(a)", position ="top.left")

这是生成的图表:

Graph of total Al - The graph has no October/2014 or December 2015 on it.

如何修改代码,使其在2014年10月和2015年12月显示为x轴上的标签 - 只是作为已显示的数字?提前致谢。这是现在要做的最后一件事!

0 个答案:

没有答案