Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(ggplot2)
- #Generate the data
- df <- data.frame(gp = factor(rep(letters[1:3], each = 10)),y = rnorm(30))
- #Set Aesthetic attributes and assign Geometric objects
- ggplot(df, aes(x = gp, y = y)) +geom_point()
- #Box plot
- ggplot(df, aes(x = gp, y = y)) +geom_boxplot()
- #add panel
- df$z<-df$y+rnorm(30)
- ggplot(df, aes(x = z, y = y)) +geom_point()+facet_grid(gp~.)
- #different way to add panel
- ggplot(df, aes(x = z, y = y)) +geom_point()+facet_grid(.~gp)
- #add line and smooth it
- ggplot(df, aes(x = z, y = y)) +geom_point()+facet_grid(gp~.)+geom_smooth()
- #add line based on linear regression method and smooth it
- ggplot(df, aes(x = z, y = y)) +geom_point()+facet_grid(gp~.)+geom_smooth(method='lm')
- #Draw line plot
- ggplot(df, aes(x = z, y = y)) +geom_line()+facet_grid(gp~.)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement