R语言 ggplot作图
作者:互联网
参考用书:
# apricoter ggplot2超详细讲解 https://www.jianshu.com/p/07f7931a00db
# Data Visualization https://socviz.co/makeplot.html
# 李东风 https://www.math.pku.edu.cn/teachers/lidf/docs/Rbook/html/_Rbook/ggplot2.html
# devtools::install_github("kjhealy/socviz")
代码:
# apricoter ggplot2超详细讲解 https://www.jianshu.com/p/07f7931a00db
# Data Visualization https://socviz.co/makeplot.html
# 李东风 https://www.math.pku.edu.cn/teachers/lidf/docs/Rbook/html/_Rbook/ggplot2.html
# devtools::install_github("kjhealy/socviz")
library(gapminder)
library(tidyverse)
p <- ggplot(data = gapminder,
mapping = aes(x = gdpPercap,
y = lifeExp,
color = continent)) # color & fill by variables #
p + geom_point(alpha = 0.3) + # color to all points | by variables in aes #
geom_smooth(method = "glm") +
scale_x_log10(labels = scales::dollar) +
labs(x = "GDP Per Capita", y = "Life Expectancy in Years",
title = "Economic Growth and Life Expectancy",
subtitle = "Data points are country-years",
caption = "Source: Gapminder.")
knitr::opts_chunk$set(fig.width=8, fig.height=5)
ggsave(filename = "my_figure.png") # plot = 图片若有命名 #
标签:www,语言,作图,Rbook,ggplot,html,ggplot2,https,socviz 来源: https://blog.csdn.net/weixin_42683052/article/details/121266421