0. 需求
群里看到學(xué)員求助一個圖购撼,畫它跪削。
其實就是個點圖加棍,棒棒糖圖迂求。找到了示例數(shù)據(jù)和代碼:
https://www.r-graph-gallery.com/301-custom-lollipop-chart.html
關(guān)于加數(shù)字這個操作碾盐,我覺得有點多余,如果想加可以參考以前的火山圖加標(biāo)簽揩局。
1.示例數(shù)據(jù)和示例代碼
library(tidyverse)
# Create data
data <- data.frame(
x=LETTERS[1:26],
y=abs(rnorm(26))
)
# plot
ggplot(data, aes(x=x, y=y)) +
geom_segment( aes(x=x, xend=x, y=0, yend=y)) +
geom_point( size=5, color="red", fill=alpha("orange", 0.3), alpha=0.7, shape=21, stroke=2)
2.照葫蘆畫瓢順便美化一下
library(tidyverse)
# Create data
data <- data.frame(
x=1:75,
y=abs(rnorm(75,sd = 50)),
group = sample(LETTERS[1:3],75,replace = T)
)
# plot
ggplot(data, aes(x=x, y=y)) +
geom_segment( aes(x=x, xend=x, y=0, yend=y,color = group)) +
geom_point( aes(color = group),size=2, alpha=0.7, stroke=2)+
theme_bw()
3. 大鵬一日同風(fēng)起毫玖,扶搖直上九萬里
library(ggplot2)
data <- data.frame(
x=1:25,
y=sort(abs(rnorm(25,sd = 50))),
group = sample(LETTERS[1:3],25,replace = T)
)
# Change baseline
ggplot(data, aes(x=x, y=y)) +
geom_segment( aes(x=x, xend=x, y=50, yend=y), color="grey") +
geom_point( aes(color = group), size=2) +
theme_light() +
theme(
panel.grid.major.x = element_blank(),
panel.border = element_blank(),
axis.ticks.x = element_blank()
) +
xlab("") +
ylab("Value of Y")+
coord_flip()
有意外收獲,富集分析上下調(diào)基因合并在一張圖上表示就是這樣畫出來的??凌盯。