其他
ggpolar 绘制极坐标图形
我也不知道
1引言
github 地址:
https://github.com/ShixiangWang/polar
2安装
install.packages("ggpolar")
# or
remotes::install_github("ShixiangWang/polar")
3使用
library(ggpolar)
#> Loading required package: ggplot2
data <- data.frame(x = LETTERS[1:7])
p1 <- polar_init(data, x = x)
p1
添加映射:
# Set aes value
p2 <- polar_init(data, x = x, size = 3, color = "red", alpha = 0.5)
p2
多个映射:
# Set aes mapping
set.seed(123L)
data1 <- data.frame(
x = LETTERS[1:7],
shape = c("r", "r", "r", "b", "b", "b", "b"),
color = c("r", "r", "r", "b", "b", "b", "b"),
size = abs(rnorm(7))
)
# Check https://ggplot2.tidyverse.org/reference/geom_point.html
# for how to use both stroke and color
p3 <- polar_init(data1, x = x, aes(size = size, color = color, shape = shape), alpha = 0.5)
p3
添加连线:
data2 <- data.frame(
x1 = LETTERS[1:7],
x2 = c("B", "C", "D", "E", "C", "A", "C"),
color = c("r", "r", "r", "b", "b", "b", "b")
)
p4 <- p3 + polar_connect(data2, x1, x2)
p4
polar_connect 映射不需要在 aes 里:
# Unlike polar_init, mappings don't need to be included in aes()
p5 <- p3 + polar_connect(data2, x1, x2, color = color, alpha = 0.8, linetype = 2)
p5
多个颜色映射图例:
# Use two different color scales
if (requireNamespace("ggnewscale")) {
library(ggnewscale)
p6 = p3 +
new_scale("color") +
polar_connect(data2, x1, x2, color = color, alpha = 0.8, linetype = 2)
print(p6 + scale_color_brewer())
print(p6 + scale_color_manual(values = c("darkgreen", "magenta")))
}
#> Loading required namespace: ggnewscale
4结尾
可以用来展示不同数据之间的关联性。
欢迎加入生信交流群。加我微信我也拉你进 微信群聊 老俊俊生信交流群
(微信交流群需收取20元入群费用(防止骗子和便于管理)
)。
老俊俊微信:
知识星球:
所以今天你学习了吗?
今天的分享就到这里了,敬请期待下一篇!
最后欢迎大家分享转发,您的点赞是对我的鼓励和肯定!
如果觉得对您帮助很大,赏杯快乐水喝喝吧!
往期回顾
◀...