当前正在尝试利用cut()和scale_fill_manual填充树形图。故障排除后,我不确定为什么我的输出保持原来的状态。据我所知,scale_fill_manual()仅响应整数而不是小数。关于克服这个问题有什么想法吗?我希望我的输出与第一个代码块相似。
ggplot(tree_values,aes(area = fidelity_prop,
label = routine_type,
fill = cut(current_score,c(-Inf, .75,.89, Inf))),
stat = "identity")+
geom_treemap()+
geom_treemap_text(fontface = "italic", colour = "white", place = "centre",
grow = F, reflow = T)+
scale_fill_manual(name = "Fidelity Condition",
values = c("(-Inf,.75]" = "red",
"(.75,.89]" = "yellow",
"(.89,Inf]" = "green"),
labels = c("Not Adequate",
"Needs Improvement",
"Adequate"))
如果我将代码更改为以下格式:
ggplot(tree_values,aes(area = fidelity_prop,
label = routine_type,
fill = cut(current_score,c(-Inf, 75,89, Inf))),
stat = "identity")+
geom_treemap()+
geom_treemap_text(fontface = "italic", colour = "white", place = "centre",
grow = F, reflow = T)+
scale_fill_manual(name = "Fidelity Condition",
values = c("(-Inf,75]" = "red",
"(75,89]" = "yellow",
"(89,Inf]" = "green"),
labels = c("Not Adequate",
"Needs Improvement",
"Adequate"))
编辑:dput()输出:
structure(list(routine_type = c("Behavior Management", "Daily Language/Opening Routines",
"Positive Climate", "Productivity", "Schedule Allows Adequate ELA Instruction",
"Schedule Components Match Journeys TE and Time Guidelines",
"Skills and Strategies", "Small Group Time Doesn't Compromise Whole Group",
"Small Group/Independent Studies", "Word Work"), fidelity_summary = c(8.65,
15.8, 7.9, 9.65, 0.9, 0.8, 21.6, 0.8, 8.35, 21.95), fidelity_prop = c(0.0670542635658915,
0.122480620155039, 0.0612403100775194, 0.0748062015503876, 0.00697674418604651,
0.0062015503875969, 0.167441860465116, 0.0062015503875969, 0.0647286821705426,
0.17015503875969), high_score = c(0.09302326, 0.1627907, 0.09302326,
0.09302326, 0.007751938, 0.007751938, 0.2325581, 0.007751938,
0.09302326, 0.2093023), current_score = c(0.720833300895835,
0.752380941632653, 0.658333303708335, 0.804166630479168, 0.8999999982,
0.7999999984, 0.720000122400021, 0.7999999984, 0.695833302020835,
0.812963062325115)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-10L))
答案 0 :(得分:0)
完成更多工作之后。 @Camille显示我的值的格式与cut创建它们的方式不同。以下代码适用于我的用例。
ggplot(tree_values,aes(area = fidelity_prop,
label = routine_type,
fill = cut(current_score,c(-Inf, 0.75,0.9, Inf))),
stat = "identity")+
geom_treemap()+
geom_treemap_text(fontface = "italic", colour = "white", place = "centre",
grow = F, reflow = T)+
scale_fill_manual(name = "Fidelity Condition",
values = c("(-Inf,0.75]" = "red",
"(0.75,0.9]" = "yellow",
"(0.90,Inf]" = "green"),
labels = c("Not Adequate",
"Needs Improvement",
"Adequate"))