美文网首页R语言做图
R语言ggplot2画一个漂亮的气泡图

R语言ggplot2画一个漂亮的气泡图

作者: 小明的数据分析笔记本 | 来源:发表于2021-03-14 12:20 被阅读0次
    data("airquality")
    head(airquality)
    library(dplyr)
    airquality%>%
      filter(Month=="7" | Month == "8" | Month == "9") -> aq_trim
    aq_trim$Month <- factor(aq_trim$Month,
                            labels = c("July", "August", "September"))
    #fill <- c("#56B4E9", "#F0E442", "violetred1")
    fill = c("steelblue", "yellowgreen", "violetred1")
    p6 <- ggplot(aq_trim, aes(x = Day, y = Ozone, size = Wind, fill = Month)) +
      geom_point(shape = 21) +
      ggtitle("Air Quality in New York by Day") +
      labs(x = "Day of the month", y = "Ozone (ppb)",
           size = "Wind Speed (mph)", fill = "Months") +
      scale_x_continuous(breaks = seq(1, 31, 5),
                         limits = c(0,31)) +
      scale_fill_manual(values = fill) +
      scale_size(range = c(1, 20)) +
      theme(legend.position="bottom", 
            legend.direction="horizontal",
            legend.box = "vertical",
            legend.key.size = unit(1, "cm"),
            axis.line = element_line(size=1, colour = "black"),
            panel.grid.major = element_blank(),
            panel.grid.minor = element_blank(),
            panel.border = element_blank(),
            panel.background = element_blank(),
            axis.text.x=element_text(colour="black", size = 10),
            axis.text.y=element_text(colour="black", size = 10),
            legend.key = element_blank())+
      #xlim(0,31)+
      ylim(0,200)
    p6
    
    image.png

    相关文章

      网友评论

        本文标题:R语言ggplot2画一个漂亮的气泡图

        本文链接:https://www.haomeiwen.com/subject/wesqcltx.html