R语言极坐标揭示条形图和鸡冠花图间的有趣联系
library(tidyverse)
bar <- ggplot(data = diamonds) +
geom_bar(
mapping = aes(x = cut, fill = cut),
show.legend = FALSE,
width = 1
) +
theme(aspect.ratio = 1) +
labs(x = NULL, y = NULL)
bar + coord_flip()

bar + coord_polar()

x和fill都改成clarity
library(tidyverse)
bar <- ggplot(data = diamonds) +
geom_bar(
mapping = aes(x = clarity, fill = clarity),
show.legend = FALSE,
width = 1
) +
theme(aspect.ratio = 1) +
labs(x = NULL, y = NULL)
bar + coord_flip()

bar + coord_polar()

x参数改成cut,fill参数改成clarity
library(tidyverse)
bar <- ggplot(data = diamonds) +
geom_bar(
mapping = aes(x = cut, fill = clarity),
show.legend = FALSE,
width = 1
) +
theme(aspect.ratio = 1) +
labs(x = NULL, y = NULL)
bar + coord_flip()

bar + coord_polar()

x参数改成clarity,fill参数改成cut,show.legend=TRUE
library(tidyverse)
bar <- ggplot(data = diamonds) +
geom_bar(
mapping = aes(x = clarity, fill = cut),
show.legend = FALSE,
width = 1
) +
theme(aspect.ratio = 1) +
labs(x = NULL, y = NULL)
bar + coord_flip()

bar + coord_polar()
library(tidyverse)
bar <- ggplot(data = diamonds) +
geom_bar(
mapping = aes(x = clarity, fill = cut),
show.legend = TRUE,
width = 1
) +
theme(aspect.ratio = 1) +
labs(x = NULL, y = NULL)

参考文献:R数据科学---[新西兰]哈德利 威克姆,[美]加勒特 格罗勒芒德---陈光欣[译] 北京:人民邮电出版社
开发环境:RStudio
- 点赞
- 收藏
- 关注作者
评论(0)