R语言ggplot2每周一图活动:第二周~气泡图展示女性科研工作者所占比例

2022-05-23 15:47:53 浏览数 (1)

今天推文是R语言ggplot2每周一图活动第二周的示例数据和代码

重复的内容是

image.png

数据和代码的链接是

https://github.com/z3tt/TidyTuesday/blob/main/R/2019_16_DataVizMistakes.Rmd

当然我没有完全重复这个图的代码,而是做了一些修改,下面是修改过后的代码出图

image.png

以下是作图代码

代码语言:javascript复制
dat01<-read.csv("women_research.csv")
head(dat01)

library(ggplot2)

ggplot(data = dat01,aes(x=percent_women,y=field)) 
  geom_point()

ggplot(data = dat01,aes(x=percent_women,y=field)) 
  geom_point(aes(size=percent_women))

ggplot(data = dat01,aes(x=percent_women,y=field)) 
  geom_point(aes(size=percent_women,color=country))

ggplot(data = dat01,aes(x=percent_women,y=field)) 
  geom_point(aes(size=percent_women,color=country)) 
  theme(legend.position = "bottom")

ggplot(data = dat01,aes(x=percent_women,y=field)) 
  geom_point(aes(size=percent_women,color=country)) 
  theme(legend.position = "bottom",
        legend.direction = "vertical")

ggplot(data = dat01,aes(x=percent_women,y=field)) 
  geom_point(aes(size=percent_women,color=country)) 
  theme(legend.position = "bottom",
        legend.direction = "vertical") 
  guides(color=guide_legend(ncol=2))

ggplot(data = dat01,aes(x=percent_women,y=field)) 
  geom_point(aes(size=percent_women,color=country)) 
  theme(legend.position = "bottom",
        legend.direction = "vertical",
        panel.background = element_blank()) 
  guides(color=guide_legend(ncol=2))

ggplot(data = dat01,aes(x=percent_women,y=field)) 
  geom_point(aes(size=percent_women,color=country)) 
  theme(legend.position = "bottom",
        legend.direction = "vertical",
        panel.background = element_blank(),
        panel.border = element_rect(fill = "transparent")) 
  guides(color=guide_legend(ncol=2))

ggplot(data = dat01,aes(x=percent_women,y=field)) 
  geom_point(aes(size=percent_women,color=country),
             alpha=0.5) 
  theme(legend.position = "bottom",
        legend.direction = "vertical",
        panel.background = element_blank(),
        panel.border = element_rect(fill = "transparent")) 
  guides(color=guide_legend(ncol=2,title.hjust = 0.2)) 
  scale_size_continuous(name="AA",range = c(1,10))




colors12<-readr::read_lines("color12.txt")

ggplot(data = dat01,aes(x=percent_women,y=field)) 
  geom_point(aes(size=percent_women,color=country),
             alpha=0.5) 
  theme(legend.position = "bottom",
        legend.direction = "vertical",
        panel.background = element_blank(),
        panel.border = element_rect(fill = "transparent"),
        legend.key = element_blank()) 
  guides(color=guide_legend(ncol=2,title.hjust = 0.2)) 
  scale_size_continuous(name="AA",range = c(1,10)) 
  scale_color_manual(name="BB",
                     values = colors12)

ggplot(data = dat01,aes(x=percent_women,y=field)) 
  geom_point(aes(size=percent_women,color=country),
             alpha=0.5) 
  theme(legend.position = "bottom",
        legend.direction = "vertical",
        panel.background = element_blank(),
        panel.border = element_rect(fill = "transparent"),
        legend.key = element_blank()) 
  guides(color=guide_legend(ncol=2,title.hjust = 0.2)) 
  scale_size_continuous(name="AA",range = c(1,10)) 
  scale_color_manual(name="BB",
                     values = colors12) 
  labs(x=NULL,y=NULL,title = "ABCDE") 
  geom_vline(xintercept = 0.5,color="grey",lty="dashed") 
  geom_vline(xintercept = 0.4,color="grey",lty="dashed") 
  geom_vline(xintercept = 0.3,color="grey",lty="dashed") 
  geom_vline(xintercept = 0.2,color="grey",lty="dashed") 
  geom_vline(xintercept = 0.1,color="grey",lty="dashed")

0 人点赞