r - Combine 2 plots (ggplot) into one plot and differenciate them -


i have problem similar following example. want differentiate lines different group; example, want distinguish "m" sexe cdf group 1 , "m" sexe cdf group 2.

library(ggplot2) sexe <- rep(c("m", "w", "x"), 50) weight1 <- runif(150, 30, 90) weight2 <- runif(150, 30, 90) visual1 = data.frame(sexe = sexe, weight = weight1) visual2 = data.frame(sexe = sexe, weight = weight2) visual1$group <- 1 visual2$group <- 2  visual12 <- rbind(visual1, visual2)   p <- ggplot(dat = visual12, aes(x = as.numeric(weight), group = interaction(group, sexe), col = sexe)) +    #   geom_point(dat = dat2, aes(x = as.numeric(dura), col = type_de_terminal)) +   stat_ecdf(geom = "step") +   #   scale_colour_discrete(guide = guide_legend(override.aes = list(alpha = 1))) +   scale_colour_brewer(name = "sexe", palette = "set1") +   theme(axis.text = element_text(size = 15), legend.justification = c(1, 0),         legend.position = c(1, 0), axis.text.x = element_text(angle = 45, vjust = 1, hjust=1)) +    ylab("cdf") + xlab("...") + theme_bw() +   #    scale_y_continuous(limits=c(0,1), labels= percent) +   ggtitle("cumulative distribution function of ...")    #    scale_x_log10(limits = c(1,1e3), breaks = c(10 , 100))   p 

what if change linetype group?

p <- ggplot(dat = visual12, aes(x = as.numeric(weight),              group = interaction(group, sexe),              linetype=factor(group), col = sexe)) +             stat_ecdf(geom = "step") +            scale_colour_brewer(name = "sexe", palette = "set1") +      theme(axis.text = element_text(size = 15),             legend.justification = c(1, 0),            legend.position = c(1, 0),             axis.text.x = element_text(angle = 45, vjust = 1, hjust=1)) +       ylab("cdf") + xlab("...") + theme_bw() +            ggtitle("cumulative distribution function of ...")       p 

enter image description here


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -