Advertisement
Guest User

Untitled

a guest
Aug 5th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. library(ggplot2)
  2. #Generate the data
  3. df <- data.frame(gp = factor(rep(letters[1:3], each = 10)),y = rnorm(30))
  4. #Set Aesthetic attributes and assign Geometric objects
  5. ggplot(df, aes(x = gp, y = y)) +geom_point()
  6. #Box plot
  7. ggplot(df, aes(x = gp, y = y)) +geom_boxplot()
  8. #add panel
  9. df$z<-df$y+rnorm(30)
  10. ggplot(df, aes(x = z, y = y)) +geom_point()+facet_grid(gp~.)
  11. #different way to add panel
  12. ggplot(df, aes(x = z, y = y)) +geom_point()+facet_grid(.~gp)
  13. #add line and smooth it
  14. ggplot(df, aes(x = z, y = y)) +geom_point()+facet_grid(gp~.)+geom_smooth()
  15. #add line based on linear regression method and smooth it
  16. ggplot(df, aes(x = z, y = y)) +geom_point()+facet_grid(gp~.)+geom_smooth(method='lm')
  17. #Draw line plot
  18. ggplot(df, aes(x = z, y = y)) +geom_line()+facet_grid(gp~.)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement