Here is the csv data: https://www.dropbox.com/s/87bwvhyo6i4f68u/test.csv , first column is the date and second column is the corresponding value.
I would like to plot such picture as made in excel: https://www.dropbox.com/s/13wyk1aeajgs6fq/test.png . Note: the ylim in the plot is changed to the logarithmic scale (base 10), which can the picture more better than the original one. I would like to this in R, especially using ggplot making it beautiful, but I can not. So I hope you can help.
ba <- as.data.frame(fread("test.csv"))
plot(as.factor(ba[, 1]), ba[, 2], log = "y", xaxt = "n", xlab = "")
idx <- seq(1, 100, length = 10)
labels <- ba[, 1]
labels <- labels[idx]
axis(1, seq(1, 100, length = 10), par("usr")[3], srt = 45, labels = labels,
adj = 1, xpd = TRUE)
Thanks.
EDIT:
[Below is the answer from rawr]. That is perfect.
tmp <- read.csv('~/desktop/test.csv', stringsAsFactors = FALSE,
strip.white = TRUE, header = FALSE)
tmp$V1 <- paste0(tmp$V1, '-01')
tmp <- within(tmp, {
V1 <- as.Date(V1)
date <- format(as.Date(tmp$V1, '%Y-%m-%d'), '%Y-%m')
stuff <- V2
})
par(tcl = -.1, xpd = FALSE)
with(tmp,
plot(V1, log(stuff), type = 'n', ylim = c(0,6),
col = 'royalblue1', lwd = 3, bty = 'l',
axes = FALSE, xlab = '', ylab = ''))
abline(h = 0:6, lwd = .5)
with(tmp, points(x = V1, y = log10(stuff), type = 'l',
col = 'royalblue1', lwd = 3))
par(xpd = TRUE)
axis(2, at = 0:6, cex.axis = .6,
labels = format(10 ** (0:6), scientific = FALSE, big.mark = ','), las = 2)
x <- with(tmp, seq(min(V1), max(V1), length = 12))
text(x = x, y = -.5, cex = .8, labels = format(x, '%Y-%m'), srt = 45)