r - 在不改变标题格式的情况下,如何在 R 中将括号添加到点须?
问题描述
我有一个整洁的数据框,其中包含多个模型,我将其绘制为点须图。下面我重新创建了一个类似的数据框。此图需要说明有关预测变量的信息的标题,并且在没有括号时格式正确,但是当添加括号时,它会在左下角重复。有没有办法解决这个问题,或者发生这种情况的原因?我也有兴趣将标题放在情节的图例下方,但尝试使用注释和标签也会导致格式问题。感谢您的任何帮助!(此外,如果这看起来很奇怪,因为 'model' 和 'term' 已经相同,实际代码中的问题是标准化模型的某些名称以使颜色正确,但在这里不应该成为问题)。
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
#graph with all elements
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 = type)))
#add aesthetics to graph
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),
plot.caption = element_text(size=8, hjust = 0)) +
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)+
labs(caption = "Note:
- notes about predictors
- additional notes
- additional notes
- additional notes
")
#look at graph, no formatting issues
full_graph
#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)
#look at graph -- caption formatting now weird
full_plot[1]
解决方案
推荐阅读
- vhdl - VHDL 数组索引和 X-optimism
- sql - 在递归问题中显示最低级别的 componentID
- javascript - 更新数组中的对象并且它可以工作,但是也添加了一个神秘的数组
- swift - Swift IQ 键盘管理器。代码在模拟器中不起作用。按下文本字段时键盘根本不会弹出
- react-native - 在后台模式下 React Native 退出应用程序
- c# - ASP.NET 核心。每个浏览器会话仅命中一次方法中的断点
- python - 使用带有通配符的用户输入搜索 CSV 文件
- java - 如何从多个 html 模板生成多页 PDF?
- java - 从 Room 数据库查询用户时出现 Java NullPointerException
- python - 为什么我的 python 子进程标准输出为空?