I want to plot a very simple line plot (timeseries chart, actually). The only thing I want is the line to appear not in black but in the first color of the default color wheel that ggplot2
uses (i.e. replace the default "black" --- which might be specified somewhere --- with the first color of the default ggplot2 color palette).
I have only come up with a non-elegant version where I manually specify the HCL value of the first color (hcl(h=15, l=65, c=100)
) - thanks to info in this answer: https://stackoverflow.com/a/8197703/1477035
Isn't there a more elegant way? I've also thought about including a factor variable which only has one value and then specifying colour=as.factor(MyFactorVariable)
, but this messes up the na.rm = T
somehow (because I need to have gaps in the line where NAs appear).
Data sample:
structure(list(Date = structure(c(15701, 15702, 15703, 15704,
15705, 15706, 15707, 15708, 15709, 15710, 15711, 15712, 15713,
15714, 15715, 15716, 15717, 15718, 15719, 15720, 15721, 15722,
15723, 15724, 15725, 15726, 15727, 15728, 15729, 15730, 15731,
15732, 15733, 15734, 15735, 15736, 15737, 15738, 15739, 15740
), class = "Date"), Additions = c(398L, 212L, 171L, 133L, 124L,
99L, 105L, 103L, 99L, 101L, 104L, 102L, 99L, 70L, 76L, 95L, 51L,
76L, 76L, 65L, 73L, 84L, 71L, 82L, 47L, 78L, 65L, 73L, 79L, 64L,
45L, NA, NA, NA, NA, NA, NA, NA, 149L, 198L)), .Names = c("Date",
"Additions"), row.names = c(NA, 40L), class = "data.frame")
Code:
p <- ggplot(data, aes(Date, Additions), na.rm = T)
p <- p + geom_line(colour=hcl(h=15, l=65, c=100)) + scale_x_date(labels = date_format("%B"))
p <- p + xlab("Date of addition") + ylab("Daily additions to user database")
p <- p + theme_minimal() + theme(plot.margin = unit(c(1,1,1,1), "cm"),
axis.title.x = element_text(vjust=-1),
axis.title.y = element_text(angle=90, vjust=0),
panel.grid.minor = element_blank(),
plot.background = element_rect(fill = rgb(0.99,0.99,0.99))
)
p
This gives: