我觉得这个问题已经有答案了,但我找不到任何关键词或已经问过的问题,所以,如果你能指出我在这个方向,那就太好了。
如果这是一个新问题,那么我如何绘制一个条形图来显示y轴上每个类别的频率?基本上我会做以下事情:
library("viridis")
library("ggpubr")
library("ggplot2")
mydata <- data.frame(var_one=c("txt_d_p", "txt_d_g", "txt_d_g", "txt_d_g", "txt_d_g", "txt_d_g", "txt_d_g", "txt_d_g", "txt_d_g", "txt_d_g", "txt_d_g", "txt_d_g", "txt_d_g", "txt_d_g", "txt_d_g", "txt_r_p", "txt_r_g", "txt_r_g", "txt_r_g", "txt_r_g", "txt_r_g", "txt_r_g", "txt_r_g", "txt_d_p", "txt_d_g"),
var_two=c("a", "b", "c", "d", "e", "f", "g", "h", "I", "j", "k", "l", "m", "n", "o", "p", "r", "s", "t", "u", "v", "w", "x", "y", "z"),
var_three=c(0.46188, 0.31936, 0.01650, 0.63738, 0.79451, 0.00103, 0.69808, 0.61855, 0.11798, 0.74683, 0.00936, 0.60407, 0.31955, 0.45244, 0.45167, 0.99412, 0.15399, 0.58647, 0.76172, 0.24870, 0.78882, 0.99829, 0.12593, 0.89372, 0.32502),
var_four=c(29, 0, 4, 8, 22, 48, 3, 14, 36, 49, 20, 46, 4, 29, 5, 1, 40, 31, 1, 4, 37, 50, 44, 26, 24),
var_five=c("cat_a", "cat_a", "cat_a", "cat_a", "cat_a", "cat_a", "cat_a", "cat_a", "cat_a", "cat_a", "cat_a", "cat_a", "cat_a", "cat_a", "cat_a", "cat_a", "cat_a", "cat_a", "cat_a", "cat_a", "cat_a", "cat_a", "cat_a", "cat_b", "cat_b"),
var_six=c(0.000308449413656507, 0.00495980196203507, 0.0080034708001948, 0.00863825071060852, 0.0080034708001948, 0.00357824635415942, 0.00824743070875437, 0.000709688303818724, 0.0080034708001948, 0.0080034708001948, 0.000308449413656507, 0.0080034708001948, 0.0080034708001948, 0.00360536192691972, 0.0080034708001948, 0.00070428323596321, 0.00360536192691972, 0.00070428323596321, 0.00563842190862566, 0.00357824635415942, 0.00360536192691972, 0.000384834606500262, 0.00824743070875437, 0.00213203535235097, 0.00378753301631295))
bars <- ggplot(mydata, aes(x=var_two, y=var_six)) +
geom_bar(stat="identity", fill="#f68060", alpha=.6, width=.4) +
coord_flip() +
xlab("") +
theme_bw() +
theme(text=element_text(size=15, face="bold"), legend.position="none", axis.text.y=element_blank())
# plot tXt
bubble_tXt <- ggplot(mydata, aes(x=var_four, y=var_two, fill=var_one)) +
geom_point(size=abs(log10(mydata$var_three)), alpha=0.5, shape=21, color="black") +
scale_size(range = c(.1, 24), name="p-adjusted") +
theme(legend.position="right") +
ylab("") +
xlab("var_four") +
guides(fill=guide_legend(override.aes=list(shape=21, size=5))) +
theme_bw() +
theme(text=element_text(size=15, face="bold"), legend.position="right") +
facet_wrap(~var_five)
ggarrange(bubble_tXt, bars, common.legend = TRUE, legend = "bottom")
但是轴不匹配,因为在多面图中的条纹。我认为在单个图中是可行的,但是我找不到方法。我该怎么做呢?
1条答案
按热度按时间nukf8bse1#
一个选项是切换到
patchwork
以粘附绘图: