Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 在ggplot中创建带有单独彩色点的分组箱线图_R_Ggplot2 - Fatal编程技术网

R 在ggplot中创建带有单独彩色点的分组箱线图

R 在ggplot中创建带有单独彩色点的分组箱线图,r,ggplot2,R,Ggplot2,我正在尝试制作一个分组箱线图(通过“majorCluster”和“treatment”变量),其中叠加了由不同变量(“aid”变量)着色的点。我尝试过的所有方法都改变了点的颜色,但位置与箱线图不匹配。提前感谢您的帮助 这是我的密码: ggplot(data = boxplot.data, aes(x=majorCluster, y=expa)) + geom_boxplot(aes(color = fct_rev(factor(treatment))), width = 0.5, siz

我正在尝试制作一个分组箱线图(通过“majorCluster”和“treatment”变量),其中叠加了由不同变量(“aid”变量)着色的点。我尝试过的所有方法都改变了点的颜色,但位置与箱线图不匹配。提前感谢您的帮助

这是我的密码:

  ggplot(data = boxplot.data, aes(x=majorCluster, y=expa)) +
  geom_boxplot(aes(color = fct_rev(factor(treatment))), width = 0.5, size = 0.4, position = position_dodge(0.8)) +
  geom_dotplot(binaxis = "y", stackdir = "center", trim = FALSE, dotsize = 0.5,position = position_dodge(0.8), aes(color = fct_rev(factor(treatment)), fill = fct_rev(factor(treatment)))) +
  theme_classic()
这是输出(所需输出=点根据“aid”变量具有不同的颜色)

以下是数据(dput):


boxplot.data将
组添加到aes调用中
geom_point
(我使用它代替
geom_dot
,因为我想这是您想要的…)

使用可填充形状进行填充,因此可以对不同的图例使用颜色和填充美学

库(tidyverse)
ggplot(数据=boxplot.data,aes(x=majorCluster,y=expa))+
几何箱线图(aes(颜色=fct\U版本(系数(处理))),宽度=0.5,尺寸=0.4,位置=位置减淡(0.8))+
几何点(位置=位置减淡(0.8),
不良事件(组=fct_rev(因子(治疗)),
填充=辅助),形状=21)+
主题(经典)

由(v0.3.0)于2020-06-09创建

boxplot.data <- structure(list(aid = c("Anti-PD-L1 A", "Anti-PD-L1 A", "Anti-PD-L1 A", 
"Anti-PD-L1 A", "Anti-PD-L1 B", "Anti-PD-L1 B", "Anti-PD-L1 B", 
"Anti-PD-L1 B", "Anti-PD-L1 C", "Anti-PD-L1 C", "Anti-PD-L1 C", 
"Anti-PD-L1 C", "Anti-PD-L1 D", "Anti-PD-L1 D", "Anti-PD-L1 D", 
"Anti-PD-L1 D", "Untreated A", "Untreated A", "Untreated A", 
"Untreated A", "Untreated B", "Untreated B", "Untreated B", "Untreated B"
), majorCluster = c("1", "2", "3", "4", "1", "2", "3", "4", "1", 
"2", "3", "4", "1", "2", "3", "4", "1", "2", "3", "4", "1", "2", 
"3", "4"), expa = c(0.00229641856789997, 0.00449718430290869, 
0.0079476155988667, 0.0323137314979365, 0.125655399176487, 0.0737804421330638, 
0.0552815368690545, 0.0467782242054685, 0.00143345514424931, 
0.0055910433498606, 0.00647918094834399, 0.0150090372519559, 
0.0167864512842503, 0.0243240630288888, 0.0404105646363485, 0.0267541240801361, 
0.00925515666671728, 0.0115509845370231, 0.0276374627000041, 
0.0438400723313962, 0.0403818878060491, 0.0481121640688924, 0.0545189407651033, 
0.0764620370634215), migr = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), tran = c(0.335015348105744, 
0.376269513326694, 0.449228611310031, 0.446682573678422, 0.842635301541922, 
0.765588148505148, 0.683233418019828, 0.610651263240787, 0.18994141256059, 
0.232057278886713, 0.281840445619523, 0.351757256110902, 0.472126089570835, 
0.599354493054942, 0.707113638164233, 0.810238120454871, 0.483691176581404, 
0.609864164601998, 0.685779002499795, 0.716753100388738, 0.743285518118052, 
0.708765108329113, 0.74453010103349, 0.912753289862157), treatment = c("Atezo", 
"Atezo", "Atezo", "Atezo", "Atezo", "Atezo", "Atezo", "Atezo", 
"Atezo", "Atezo", "Atezo", "Atezo", "Atezo", "Atezo", "Atezo", 
"Atezo", "None", "None", "None", "None", "None", "None", "None", 
"None")), row.names = c("17", "21", "31", "41", "5", "6", "7", 
"8", "9", "10", "11", "12", "13", "14", "15", "16", "111", "211", 
"311", "411", "51", "61", "71", "81"), class = "data.frame")