新手自学,想要一串代码,想看一看效果,谢谢!
想见识一下R语言之美
你好,是想要看什么样的效果呢?如果只是一串代码的话,在网上用“R 实现xxx”就能搜出来很多。
- 已编辑
要美就看可视化嘛。
library(ggplot2)
ggplot(data = diamonds,
aes(x = carat, y = price, colour = color))+
geom_point()
<sup>Created on 2021-01-11 by the reprex package (v0.3.0)</sup>
绘制航线
预期寿命vsGDP
另一个动画不知道画的啥但是看起来好愉悦
我那个回复里的“动画”是超链接,代码在链接里,就是这个:
https://www.r-graph-gallery.com/271-ggplot2-animated-gif-chart-with-gganimate.html
# Get data:
library(gapminder)
# Charge libraries:
library(ggplot2)
library(gganimate)
# Make a ggplot, but add frame=year: one image per year
ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent)) +
geom_point() +
scale_x_log10() +
theme_bw() +
# gganimate specific bits:
labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') +
transition_time(year) +
ease_aes('linear')
# Save at gif:
anim_save("271-ggplot2-animated-gif-chart-with-gganimate1.gif")