r - 在点须图之外添加其他文本
问题描述
我有一个整洁的数据框,其中包含多个模型,我将其绘制为点须图。下面我重新创建了一个类似的数据框。此图需要说明有关预测变量的信息的标题,理想情况下它会位于图例下方。我曾尝试将其作为标题、标签和注释,每次在侧面添加括号都会导致格式出现问题。有没有办法在不引起格式问题的括号的情况下在此处添加其他文本?
#create dataframe
results_df <- data.frame(
model = c("Model 1", "Model 1", "Model 1",
"Model 1", "Model 1", "Model 1",
"Model 2", "Model 2", "Model 2",
"Model 2", "Model 2", "Model 2",
"Model 3", "Model 3", "Model 3",
"Model 3", "Model 3", "Model 3",
"Model 2", "Model 2", "Model 2",
"Model 2", "Model 2", "Model 2",
"Model 2", "Model 2", "Model 2"),
estimate = c(-0.4890, 0.0966, -0.0911, -0.1700, 0.3620, 0.1980, -2.0920,
-1.1620, -1.6910,-1.5320, -0.8340, -1.4350, 0.8240, 0.9750,
0.9650, 0.5210, 0.9190, 0.9560, -0.9580, -0.1950, -1.1470,
-2.6430,-1.7420, -2.2500, -2.9990, -1.8100, -1.8270),
conf.low = c(-0.6, 0.0, -0.2,-0.6, 0.0, -0.2, -2.4, -1.8, -1.9, -2.4,
-1.8, -1.9, 0.0, 0.0, 0.0, 0.0, 0.0,0.0, -3.0, -2.0,
-1.9, -5.6, -3.6, -3.8, -3.0, -2.0, -1.9),
conf.high = c(0.9, 1.1, 1.0, 0.9, 1.1, 1.0, 0.0, 0.5, 0.7, 0.0, 0.5, 0.7,
0.9, 1.1, 1.0, 0.9, 1.1, 1.0, 0.0, 0.5, 0.7, 0.0,0.5, 0.7,
0.0, 0.5, 0.7),
term = c("A","B","C","A","B","C","A","B","C","A",
"B","C","A","B","C","A","B","C","D","E",
"F","G","H","I","J","K",
"L"),
fixed = c("Without Fixed Effects", "Without Fixed Effects", "Without Fixed Effects",
"With Fixed Effects", "With Fixed Effects", "With Fixed Effects",
"Without Fixed Effects", "Without Fixed Effects", "Without Fixed Effects",
"With Fixed Effects", "With Fixed Effects", "With Fixed Effects",
"Without Fixed Effects", "Without Fixed Effects", "Without Fixed Effects",
"With Fixed Effects", "With Fixed Effects", "With Fixed Effects",
"Without Fixed Effects", "Without Fixed Effects", "Without Fixed Effects",
"Without Fixed Effects", "Without Fixed Effects", "Without Fixed Effects",
"Without Fixed Effects", "Without Fixed Effects", "Without Fixed Effects"),
type = c("Model 1", "Model 1", "Model 1",
"Model 1", "Model 1", "Model 1",
"Model 2", "Model 2", "Model 2",
"Model 2", "Model 2", "Model 2",
"Model 3", "Model 3", "Model 3",
"Model 3", "Model 3", "Model 3",
"Model 2", "Model 2", "Model 2",
"Model 2", "Model 2", "Model 2",
"Model 2", "Model 2", "Model 2")
)
#recode model
results_df$model = results_df$type
#create dotwhisker
full_graph = dwplot(results_df,
vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2),
dot_args = list(aes(shape = fixed)),
whisker_args = list(aes(colour = model)))
#add graph elements
full_graph = full_graph +
theme_bw() +
theme(legend.justification=c(.02, .993),
legend.background = element_rect(color="gray90"),
plot.title = element_text(hjust = 0.52)) + #here is where I've tried using plot.caption and plot.tag, plot.tag.position
xlab("Coefficient Estimate") +
geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
ggtitle("Graph Title") +
scale_color_manual(name="Model",values=c("#52D871","#17D0E5","#EF5B3D"),
na.translate = F)+
scale_shape_manual(name = "Shape",values=c(16,17,16,17,16,17), na.translate = F)+
scale_fill_manual(name="Model",values = c("#52D871","#17D0E5","#EF5B3D"),
na.translate = F)
#add brackets
brackets = list(c("Bracket 1", "A", "C"),
c("Bracket 2", "D", "F"),
c("Bracket 3", "G", "I"),
c("Bracket 4","J","L"))
full_plot = full_graph %>% add_brackets(brackets)
图表图像:
解决方案
推荐阅读
- reactjs - 在 React 和 Redux 中成功执行异步操作后,如何执行方法?
- javascript - 为什么不显示谷歌地图示例?
- javascript - 以 PHP-Variable 作为传输参数的 JavaScript 调用函数
- vuejs2 - Devextreme Vue Datagrid 一起配置选择和焦点行
- objective-c - #if DEBUG 在某些设备上无法用于 TestFlight 版本
- javascript - 有没有办法修复我的 CSS 和 JavaScript 中的电子邮件和标题验证?
- r - ggplot - 堆叠的 geom_bar - 将每个 x 按 y 重新排序
- excel - 如何为特定工作表运行 VBA 代码(仅在 sheet1 中)(与活动工作表无关)?
- c# - MVC JsonResult 和 Json 的 asp.net web 表单是否有任何等效代码?
- flutter - 如何创建页面卷曲效果