Hi @ all, I work with a dataframe like the attached one. I want to plot it, so that "value" is listed on the y-axis, "year" on the x-axis and "states" as lines in the coordinate system. I tried the following code: require(ggplot) plot1<-ggplot(TEST, aes(year, value)) + geom_line(aes(colour = state)) The result could be very nice but the the lines are stacked. Maybe there is an easier way to do that? Thanks a lot for your help. Geo -- View this message in context: http://r.789695.n4.nabble.com/plot-dataframe-with-inconsistently-relations-tp4642766.html Sent from the R help mailing list archive at Nabble.com.
plot dataframe with inconsistently relations
6 messages · Geophagus, R. Michael Weylandt
On Tue, Sep 11, 2012 at 2:22 PM, Geophagus <fh at retposto.net> wrote:
Hi @ all, I work with a dataframe like the attached one.
Hi Geo, Unfortunately, there is no attached data.frame. The mail servers are somewhat draconian in what they let through. A much better way to send data is to type dput(head(DATA, 20)) which will make some odd (to you) output. However, if you copy and paste that output into the body of your email, we can simply paste it into our R sessions to exactly reproduce your data. It's really a much better way to handle sending small data sets. Perhaps try that? Cheers, Michael
I want to plot it, so that "value" is listed on the y-axis, "year" on the x-axis and "states" as lines in the coordinate system. I tried the following code: require(ggplot) plot1<-ggplot(TEST, aes(year, value)) + geom_line(aes(colour = state)) The result could be very nice but the the lines are stacked. Maybe there is an easier way to do that? Thanks a lot for your help. Geo -- View this message in context: http://r.789695.n4.nabble.com/plot-dataframe-with-inconsistently-relations-tp4642766.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Hi @ all and thanks a lot for your advises. So far I don't know the function dput. Now I read something about it and I have the following result:
TEST
year value state 1 2007 15 FL 2 2008 16 FL 3 2008 14 TX 4 2008 13 TN 5 2009 18 FL 6 2009 15 OH 7 2010 19 TX 8 2010 12 OH
dput(TEST)
structure(list(year = c(2007L, 2008L, 2008L, 2008L, 2009L, 2009L,
2010L, 2010L), value = c(15L, 16L, 14L, 13L, 18L, 15L, 19L, 12L
), state = structure(c(1L, 1L, 4L, 3L, 1L, 2L, 4L, 2L), .Label = c("FL",
"OH", "TN", "TX"), class = "factor")), .Names = c("year", "value",
"state"), class = "data.frame", row.names = c(NA, -8L))
class(TEST)
[1] "data.frame" I hope this will help you. Thank and greetings Geo -- View this message in context: http://r.789695.n4.nabble.com/plot-dataframe-with-inconsistently-relations-tp4642766p4642883.html Sent from the R help mailing list archive at Nabble.com.
On Wed, Sep 12, 2012 at 9:02 AM, Geophagus <fh at retposto.net> wrote:
Hi @ all and thanks a lot for your advises. So far I don't know the function dput. Now I read something about it and I have the following result:
TEST
year value state 1 2007 15 FL 2 2008 16 FL 3 2008 14 TX 4 2008 13 TN 5 2009 18 FL 6 2009 15 OH 7 2010 19 TX 8 2010 12 OH
dput(TEST)
structure(list(year = c(2007L, 2008L, 2008L, 2008L, 2009L, 2009L,
2010L, 2010L), value = c(15L, 16L, 14L, 13L, 18L, 15L, 19L, 12L
), state = structure(c(1L, 1L, 4L, 3L, 1L, 2L, 4L, 2L), .Label = c("FL",
"OH", "TN", "TX"), class = "factor")), .Names = c("year", "value",
"state"), class = "data.frame", row.names = c(NA, -8L))
ggplot(TEST, aes(year, value)) + geom_line(aes(colour = state)) Thank you: I'm afraid I don't see what the problem is? (Your unquoted context has "lines are stacked" IIRC) This seems entirely legible to me, but the TN line is missing because it's only a single data point. Cheers, Michael
1 day later
yes thats right. I want to see all points - so I need a line with dots -- View this message in context: http://r.789695.n4.nabble.com/plot-dataframe-with-inconsistently-relations-tp4642766p4643116.html Sent from the R help mailing list archive at Nabble.com.
On Fri, Sep 14, 2012 at 9:20 AM, Geophagus <fh at retposto.net> wrote:
yes thats right. I want to see all points - so I need a line with dots
+ geom_point() should work, but I'm not at my computer to test. Also, as I said before: please quote context.... Cheers, Michael