[R] how to group smooth line by two groups?

autumn jialincau at gmail.com
Mon Oct 22 16:31:50 CEST 2012


Hello, I have the following sample dataset.

sex <- as.factor(c(rep(0,12),rep(1,12)))
char <-
c("x","x","x","x","y","y","y","y","z","z","z","z","x","x","x","x","y","y","y","y","z","z","z","z")
a <- runif(24,0,2)
b <- runif(24,4,10)
data <- data.frame(cbind(sex,char,a,b))

I would like to generate a blak and white plot with two groups of three
smooth lines. linetypes are recognized by sex, and each line with dots,
squares and triangles according to the group of char. the following is one
group, i need to plot two, one type is solid, the other type is dotted. how
to do it?

I tried a color plot with the following code. what should i change "color"
to? 

pb <- ggplot(data, aes(x = a, y = b, 
                       color = char, linetype = factor(sex))) 

p0 <- pb +
  scale_color_manual(values = c("#00FFFF", "#FFFF00", "#00FF00")) +
  scale_linetype_manual(breaks=c("0","1"), values=c(1,2), labels = c("male",
"female")) +
  geom_smooth(method = "lm", 
              se = FALSE, # Don't add shaded confidence region
              size = 1.2, aes(group = char : sex))
<http://r.789695.n4.nabble.com/file/n4647019/1.bmp> 
Thanks a looooot!




--
View this message in context: http://r.789695.n4.nabble.com/how-to-group-smooth-line-by-two-groups-tp4647019.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list