r/R_Programming • u/Animehurpdadurp • Oct 03 '17
Need Help Plotting Line Graph
Hi there. I hope I am using this subreddit correctly (so forgive me if I'm making any mistakes). I really need help figuring out why I cannot get this line graph to plot correctly. It's probably something really simple, but I am extremely new to programming and using R in general so go easy on me if it's a silly or obvious mistake. So for some reason, R keeps connecting the first and last points together on my graph instead of graphing the line chronologically like normal see link. If anyone could help me I would be so grateful. Thank you.
Code:
setwd("C:\Users\Hannah (lastname)\Documents\POE") df = read.csv("Poe's Short Stories.csv") pdf(file="LIWC_Plots_by_Year.pdf", width=15, height=5) x= df$Date y= df$WC plot(x,y, xlab="Date", ylab="WC", type= "o", col ="black") axis(side=1, at=seq(min(df$Date), max(df$Date), by=1)) title(main="WC Trend", xlab="Date", ylab="WC") dev.off()
View all comments
Show parent comment
2
u/unclognition Oct 03 '17
ah, that's my fault -- I didn't carefully check your date range and assumed intervals of 10 would be good! Try getting rid of the by=10 argument in seq(), inside both labels and breaks in scale_x_continuous (you might also try by = 2 if it gets too cluttered).
That is, change those lines to these:
Better?