Search code examples
rmeta

Recreating a visualization


I am very new to R (1 week). I would like to recreate the following graphic for the attached dataset.

Date        Rev
1/31/2013   536209
4/30/2013   559175
7/31/2013   535081
10/31/2013  529595
1/31/2014   530919
4/30/2014   518588
7/31/2014   382156
10/31/2014  336705
1/31/2015   326286

I found a code I was attempting to revise for my situation but am having no success. Any assistance would be greatly appreciated.

rowseq <- seq(nrow(fp),1)
    par(mai=c(1,0,0,0))
    plot(fp$Rev, rowseq, pch=15,
        xlim=c(-10,12), ylim=c(0,7),
        xlab='', ylab='', yaxt='n', xaxt='n',
        bty='n')
    axis(1, seq(??,??,by=50000), cex.axis=.5)

    segments(1,-1,1,6.25, lty=3)
    segments(fp$Date, rowseq)

    text(-5,6.5, "Date", cex=.75, font=2, pos=4)
    t2 <- ifelse(!is.na(fp$Date), format(fp$Date,big.mark=","), '')
    text(-3, rowseq, t2, cex=.75, pos=2)

text(-1,6.5, "Rev", cex=.75, font=2, pos=4)
t3 <- ifelse(!is.na(fp$Rev), with(fp, paste(Rev)
text(3,rowseq, t3, cex=.75, pos=4)

Solution

  • Assuming your data is in a data.frame named dd, your sample plot looks pretty close to something like this

    library(ggplot2)
    ggplot(dd) + 
       geom_segment(aes(x=0, xend=Rev, y=Date, yend=Date)) + 
       geom_point(aes(x=Rev, y=Date), size=4) +
       xlab("Rev")
    

    enter image description here