R(week 8)

library(ggplot2)
library(tidyverse)

mtcars
dim(mtcars)
head(mtcars)

?qplot
qplot(data = mtcars, x = wt, y = mpg) +
  ggtitle(" sjdklfd skdjskfl  dsfs") + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  xlab("x") + 
  ylab("y")

grep("^geom", objects("package:ggplot2"), value = TRUE)

qplot(mpg, wt, data = mtcars, color = factor(cyl),
  geom = c("point", "line"))
qplot(mpg, wt, data = mtcars, color = cyl, 
      geom = c("point", "line"))
p <- qplot(data = mtcars, x = wt, y = mpg, shape = factor(cyl)) +
  scale_shape_manual("Number of\n Clylinder", values = c(3, 5, 8)) +
  scale_color_manual(values = c("red", "blue", "green"))
qplot(data = mtcars, x = wt, y = mpg, color = factor(gear)) +
  #facet_grid(gear~.)
  facet_grid(gear~cyl, label = label_both)
qplot(factor(mtcars$cyl), geom = "bar")

qplot(factor(mtcars$cyl), geom = "blank", fill = factor(mtcars$am),
      xlab = "", ylab = "", main = "sdfsdfsf") + 
        geom_bar(position = "dodge") + 
        scale_x_discrete(label = c("V4", "V6", "V8"))+
        scale_y_continuous(breaks = seq(0, 12, 2)) +
        theme_bw() +
        coord_flip()+
        scale_fill_grey(name = "Trans.",
                        labels = c("auto", "manual"))
ggplot() +
  geom_point(data = mtcars, mapping = aes( x = wt, y = mpg, shape = factor(cyl)),
             size = 3)+
  geom_smooth(data = mtcars, mapping = aes( x = wt, y = mpg),
              method = 'lm')
ggplot(data = mtcars, aes(x=wt, y = mpg)) + 
  geom_point(aes(color = factor(cyl)))+
  geom_smooth(method = 'lm')
                        
                        
                        
                        
                        
                        
      

  

posted @ 2021-04-19 17:38  sinEagle  阅读(32)  评论(0编辑  收藏  举报