R学习与可视化

R语言基础作图三(饼图)

2020-02-12  本文已影响0人  多啦A梦的时光机_648d

一:饼图

ggplot(data=mpg,aes(x=1,fill=fl))+geom_bar() + coord_polar(theta='y')

coord_polar是极坐标的意思,区别以往的笛卡尔坐标。coord_polar()作用是把把笛卡尔坐标变换为极坐标。该函数有theta,start,direction三个参数,后者者顶多是图的微调,需要了解可以查看帮助文件,theta才是关键。极坐标参数theta有两个指标半径和角度,就饼图而言,各部分内容的角度不同,半径相同;而默认theta=”x”,即将x映射为角度,剩下的y映射为半径。这些为前期准备,下面一步步分解这个过程。

ggplot(data=mpg, aes(x=1, fill=fl)) + geom_bar()
first
ggplot(data=mpg, aes(x=1, fill=fl)) + geom_bar() + coord_polar(theta='y')
## theta='y' 指将y映射为角度,x为半径。相反,theta='x'则是指将x映射为角度,y为半径,后者生成眼图。
y映射为角度
ggplot(data=mpg, aes(x=1, fill=fl)) + geom_bar() + coord_polar(theta='y')
眼图(x映射为角度)
上一篇 下一篇

猜你喜欢

热点阅读