如何让scale_fill_manual使用十进制值?
How to make scale_fill_manual utilize decimal values?
目前正在尝试利用 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))
在完成更多工作之后。 @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"))
目前正在尝试利用 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))
在完成更多工作之后。 @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"))