我使用ggplot和过去十年中特定管理行动的一些数据制作了一个图表。该图表看起来很棒,但是在绘制的线条内部出现了一些垂直的白色空格。有没有办法去掉这些线?我猜测它们是由我的数据分组(group=1)造成的。任何帮助将不胜感激。我的代码如下。
另外,我已经使用了this stackoverflow问题作为指导。
另外,我已经使用了this stackoverflow问题作为指导。
library(scales)
# Build data frame.
a7.data <- data.frame(date = seq(as.Date("2002/01/01"), as.Date("2013/05/01"), by="day"))
a7.data$year <- as.numeric(format(as.Date(a7.data$date), format="%Y"))
a7.data$month <- as.numeric(format(as.Date(a7.data$date), format="%m"))
a7.data$day <- as.numeric(format(as.Date(a7.data$date), format="%d"))
a7.data$status <- "Yes"
a7.data$filler_value <- 0
# Edit data frame for dates in which the management action was "no".
a7.data$status[a7.data$date >= "2002/01/01" & a7.data$date < "2002/07/01"] <- "No"
a7.data$status[a7.data$date >= "2005/05/20" & a7.data$date < "2005/08/25"] <- "No"
a7.data$status[a7.data$date >= "2005/12/31" & a7.data$date < "2006/04/12"] <- "No"
a7.data$status[a7.data$date >= "2006/11/06" & a7.data$date < "2006/12/31"] <- "No"
a7.data$status[a7.data$date >= "2007/01/31" & a7.data$date < "2007/07/02"] <- "No"
a7.data$status[a7.data$date >= "2008/02/01" & a7.data$date < "2009/08/11"] <- "No"
a7.data$status[a7.data$date >= "2010/02/28" & a7.data$date < "2010/03/15"] <- "No"
a7.data$status[a7.data$date >= "2010/05/09" & a7.data$date < "2010/07/07"] <- "No"
# Create a new column that creates a dummy year with which to plot the data in ggplot using faceting.
a7.data <- transform(a7.data, doy = as.Date(paste(1970, month, day, sep="/")))
# Custom colors.
ccolors <- c("#086CA2", "#FF8B00")
# ggplot code.
bb <- ggplot(a7.data, aes(doy, filler_value)) +
geom_line(aes(color=status, group=1), size=15, alpha=0.9) +
scale_x_date(label=date_format("%b"), breaks = "month") +
xlab("") + ylab("") + facet_grid(year~., scales="free") +
theme_bw() + theme(axis.text.y=element_blank()) +
theme(axis.ticks.y=element_blank()) +
scale_color_manual(values=ccolors, name="Article VII Restrictions?")
# Display plot.
bb
Jan
左右的空白处吗? - Ricardo Saporta