With this approach. I have a line plot graph. I want to plot ‘two’ line plot on the same graph. How can I simply add that data,
The data is in the form
1 5 10
2 8 20
3 9 30
I want to plot the X as column1 and the other two columns along the y axis.
-----
# Commands
2
3 library(ggplot2)
4
5 req <- read.table("stats_quick_sort.dat")
6
7 summary(req)
8
9 xx <- req$V1
10 yy <- req$V2
11
12
13 png('stats_sort_image.png', width=800, height=600)
14 gg <- qplot(xx, yy) + geom_line()
15 print(gg)
16 dev.off()
As an aside — if you provide a reproducible example that demonstrates your problem, it is much easier for us to help you. I’m going to give you a reproducible example as an answer so you see what I mean. It means anyone can copy and paste the code and it’ll work (whereas I couldn’t copy/paste your code because I don’t have
stats_quick_sort.dat).To plot multiple lines on a plot you just call
geom_lineagain, feeding in thexandyvariables toaes:In general, if you want to add other information to your plot that you did not supply in the initial
qplot/ggplotcall, then just feed it in toaes. You want a line? Usegeom_line. You want new x and y coordinates? Then usegeom_line(aes(x= .., y=..)). And so on.