An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130314/3afd7bec/attachment.pl>
plotting
7 messages · R. Michael Weylandt, David L Carlson, John Kane +2 more
I think you'll find this easiest with ggplot2: library(ggplot2) ggplot(dat, aes(x = value, y = time, color = group, symbol = id)) + geom_point() # symbol = might not be the right argument -- I'm doing this from memory or similar.... MW
On Thu, Mar 14, 2013 at 3:46 PM, li li <hannah.hlx at gmail.com> wrote:
Hi alL,
I have a data frame with 4 columns: "value", "time", "group" and "id".
I would like to plot "value" vs. "time" with different colors for
different levels of "group" and
different symbols for different values of "id".
I think I could do this but I would like to see what is an easier way to
plot
the data this way.
Thank you vey much.
Hanna
[[alternative HTML version deleted]]
______________________________________________ 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.
It is easy to do in base graphics, but probably a bad idea just because it
is very hard to decode the symbol/color combinations. I added a crude
legend:
# Provide reproducible data
set.seed(42)
value <- round(rnorm(20), 2)
time <- round(runif(20)*10, 1)
group <- sample(1:4)
id <- sample(1:5)
dta <- data.frame(value, time, group, id)
# Plot and legend
plot(value~time, pch=id+20, col=group, bg=group, cex=1.25)
legend("bottomright", as.character(1:4), pch=16,
col=1:4, bty="n", inset=c(0, .045), title="Group")
legend("bottomright", as.character(1:5), pch=21:25, col="gray",
inset=c(.1, 0), bty="n", title="ID")
----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- project.org] On Behalf Of R. Michael Weylandt Sent: Thursday, March 14, 2013 10:51 AM To: li li Cc: r-help Subject: Re: [R] plotting I think you'll find this easiest with ggplot2: library(ggplot2) ggplot(dat, aes(x = value, y = time, color = group, symbol = id)) + geom_point() # symbol = might not be the right argument -- I'm doing this from memory or similar.... MW On Thu, Mar 14, 2013 at 3:46 PM, li li <hannah.hlx at gmail.com> wrote:
Hi alL, I have a data frame with 4 columns: "value", "time", "group" and
"id".
I would like to plot "value" vs. "time" with different colors for different levels of "group" and different symbols for different values of "id". I think I could do this but I would like to see what is an easier
way to
plot
the data this way.
Thank you vey much.
Hanna
[[alternative HTML version deleted]]
______________________________________________ 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.
______________________________________________ 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.
Also going from memory Michael's ggplot should almost work but I think yo need to change symbol = id in the aes statement to geom_point(aes(shape = id)) although it may work in the first aes() statement. John Kane Kingston ON Canada
-----Original Message----- From: michael.weylandt at gmail.com Sent: Thu, 14 Mar 2013 15:51:21 +0000 To: hannah.hlx at gmail.com Subject: Re: [R] plotting I think you'll find this easiest with ggplot2: library(ggplot2) ggplot(dat, aes(x = value, y = time, color = group, symbol = id)) + geom_point() # symbol = might not be the right argument -- I'm doing this from memory or similar.... MW On Thu, Mar 14, 2013 at 3:46 PM, li li <hannah.hlx at gmail.com> wrote:
Hi alL,
I have a data frame with 4 columns: "value", "time", "group" and
"id".
I would like to plot "value" vs. "time" with different colors for
different levels of "group" and
different symbols for different values of "id".
I think I could do this but I would like to see what is an easier way
to
plot
the data this way.
Thank you vey much.
Hanna
[[alternative HTML version deleted]]
______________________________________________ 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.
______________________________________________ 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.
____________________________________________________________ FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
It is easy to do in base graphics, but probably a bad idea just because it is very hard to decode the symbol/color combinations.
I just appropriated your data set and tried it in ggplot2 and your objection looks valid there as well.
And Michael was right, the shape command can go in the first aes statement.
library(ggplot2)
p <- ggplot(dta , aes(time, value,
shape = as.factor(id) , colour =as.factor(group ))) +
geom_point()
p
John Kane
Kingston ON Canada
-----Original Message-----
From: dcarlson at tamu.edu
Sent: Thu, 14 Mar 2013 11:23:18 -0500
To: michael.weylandt at gmail.com, hannah.hlx at gmail.com
Subject: Re: [R] plotting
It is easy to do in base graphics, but probably a bad idea just because
it
is very hard to decode the symbol/color combinations. I added a crude
legend:
# Provide reproducible data
set.seed(42)
value <- round(rnorm(20), 2)
time <- round(runif(20)*10, 1)
group <- sample(1:4)
id <- sample(1:5)
dta <- data.frame(value, time, group, id)
# Plot and legend
plot(value~time, pch=id+20, col=group, bg=group, cex=1.25)
legend("bottomright", as.character(1:4), pch=16,
col=1:4, bty="n", inset=c(0, .045), title="Group")
legend("bottomright", as.character(1:5), pch=21:25, col="gray",
inset=c(.1, 0), bty="n", title="ID")
----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- project.org] On Behalf Of R. Michael Weylandt Sent: Thursday, March 14, 2013 10:51 AM To: li li Cc: r-help Subject: Re: [R] plotting I think you'll find this easiest with ggplot2: library(ggplot2) ggplot(dat, aes(x = value, y = time, color = group, symbol = id)) + geom_point() # symbol = might not be the right argument -- I'm doing this from memory or similar.... MW On Thu, Mar 14, 2013 at 3:46 PM, li li <hannah.hlx at gmail.com> wrote:
Hi alL, I have a data frame with 4 columns: "value", "time", "group" and
"id".
I would like to plot "value" vs. "time" with different colors for different levels of "group" and different symbols for different values of "id". I think I could do this but I would like to see what is an easier
way to
plot
the data this way.
Thank you vey much.
Hanna
[[alternative HTML version deleted]]
______________________________________________ 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.
______________________________________________ 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.
______________________________________________ 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.
____________________________________________________________ GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130314/b243457d/attachment.pl>
On 03/15/2013 02:46 AM, li li wrote:
Hi alL,
I have a data frame with 4 columns: "value", "time", "group" and "id".
I would like to plot "value" vs. "time" with different colors for
different levels of "group" and
different symbols for different values of "id".
I think I could do this but I would like to see what is an easier way to
plot
the data this way.
Hi Hanna, You will probably want to dress this up a bit: # rustle up some data test.df<-data.frame(value=rnorm(80)+4,time=sample(0:23,80,TRUE), group=rep(LETTERS[1:4],each=20),id=rep(1:4,each=20)) # plot it plot(test.df$time,test.df$value,col=test.df$group,pch=test.df$id) Jim