[英]R plotting a graph with confidence intervals
I have a dataframe that looks like this -我有一个 dataframe,看起来像这样 -
df = data.frame(recall=c(0.55,0.62,0.43,0.61,0.19,0.14,0,0.19,0.33,0.33,0,0.33),
type= c("Phone numbers","Phone numbers","Phone numbers","Phone numbers","Emails","Emails","Emails","Emails","URLs","URLs","URLs","URLs"),
model=c("Cognition","TS-SAR","TS-ABINet","TS-RobustScanner",
"Cognition","TS-SAR","TS-ABINet","TS-RobustScanner",
"Cognition","TS-SAR","TS-ABINet","TS-RobustScanner"),
lb=c(0.47,0.55,0.35,0.53,
0.07,0.04,0,0.07,
0.14,0.14,0,0.14),
ub=c(0.63,0.7,0.51,0.69,
0.30,0.24,0,0.3,
0.52,0.52,0,0.52))
It consists of the results of 4 'text detection in image' ML models.它由 4 个“图像中的文本检测”ML 模型的结果组成。 The recall
column has the recall metric values for each model, based on the type
of text being detected (either Phone number, email or URLs). recall
列具有每个 model 的召回指标值,具体取决于检测到的文本type
(电话号码、email 或 URL)。 The ub
and lb
columns have the lower and bound values of recall of a 95% confidence interval. ub
和lb
列具有 95% 置信区间召回率的下限值和界限值。
Objective客观的
I'd like to plot this in one graph using R.我想使用 R 在一张图中显示 plot。
Here is my attempt using ggplot2
这是我尝试使用ggplot2
pd <- position_dodge(width=0.2)
ggplot(df, aes(model,recall, color=type)) +
geom_point(aes(shape=type),size=4, position=pd) +
scale_color_manual(name="Type",values=c("coral","steelblue")) +
scale_shape_manual(name="Type",values=c(17,19)) +
theme_bw() +
scale_x_continuous("Model", breaks=1:length(model), labels=model) +
scale_y_continuous("Recall values") +
geom_errorbar(aes(ymin=lb,ymax=ub),width=0.1,position=pd)
However this gives me an error message然而,这给了我一条错误信息
Error in check_breaks_labels(breaks, labels): object 'model' not found check_breaks_labels(breaks, labels) 错误:object 未找到“模型”
Any ideas why this could be an error?任何想法为什么这可能是一个错误? Also I'm open to new ways of plotting this data, if anyone has suggestions.如果有人有建议,我也愿意接受绘制这些数据的新方法。 Thanks!谢谢!
Your code needs a couple of tweaks.您的代码需要进行一些调整。
Firstly, ggplot
only uses non-standard evaluation inside aes
, so the use of model
inside scale_x_continuous
results in a " model
not found" error.首先, ggplot
仅在aes
内部使用非标准评估,因此在model
内部使用scale_x_continuous
导致“ model
”错误。
Secondly, the x axis isn't continuous.其次,x 轴不连续。 It's discrete.它是离散的。 And the breaks / labels will be correct if you don't specify an x axis scale at all.如果您根本不指定 x 轴刻度,则中断/标签将是正确的。 You can just take the line out and trust the defaults.你可以把线去掉并相信默认值。
Thirdly, the type
variable has three levels, so you need three values in the color and shape scales.第三, type
变量具有三个级别,因此在颜色和形状尺度中需要三个值。
Putting these together, we have:把这些放在一起,我们有:
position <- position_dodge(width = 0.2)
ggplot(df, aes(model, recall, color = type)) +
geom_point(aes(shape = type), size = 4, position = pd) +
geom_errorbar(aes(ymin = lb, ymax = ub), width = 0.1, position = pd) +
scale_color_manual("Type", values = c("coral", "steelblue", "green4")) +
scale_shape_manual("Type", values = c(17, 19, 18)) +
scale_y_continuous("Recall values") +
theme_bw(base_size = 16)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.