【发布时间】:2017-08-23 03:26:11
【问题描述】:
各位,请帮忙。什么都试过了。经历了不同的选择。有因素和没有因素,有 scale_fill_manual 和 scale_fill_gradient... 不幸的是,没有任何效果:(
我创建了一个箱线图
income.boxplot <- ggplot(income.by.state, aes(x = State, y = Estimate)) +
geom_boxplot() +
coord_flip() + scale_x_discrete(limits = rev(levels(income$State))) +
labs(title = "Median household income by state",
subtitle = "Source: 2011-2015 American Community Survey") +
theme(plot.title = element_text(hjust = 0.5)) +
labs(x = "State",
y = "Median household income",
fill = "Median household income") +
theme_fivethirtyeight() +
theme(axis.line.x = element_line(size = .5, colour = "black"),
axis.title = element_text(size = 14),
legend.position = "right",
legend.direction = "vertical",
legend.box = "vertical",
legend.key.size = unit(0.7, "cm"),
legend.text = element_text(size = 10),
text = element_text(family = "OfficinaSanITC-Book"),
plot.title = element_text(family = "OfficinaSanITC-Book"))
income.boxplot
但我无法为它创建调色板。想做橙色-蓝色,收入低,橙色,渐变成高/蓝色。
有时我有因子错误(x = 状态,y = 估计):未使用的参数(y = 估计) 等等。
我的数据看起来像
1 Ziebach County Median Household Income ($) South Dakota 35119
2 Zavala County Median Household Income ($) Texas 26672
3 Zapata County Median Household Income ($) Texas 32162
4 Yuma County Median Household Income ($) Colorado 43105
更新!
我发现了一些东西。 link 但是当我尝试用 color = as.integer(Estimate), group = Estimate 来做这件事时,它变得很糟糕。所以,以某种方式是可能的。
更新 2!
【问题讨论】:
-
您是否在 ggplot 的
aes()中包含了fill = Estimate?否则scale_fill_XXX()函数将不知道要使用什么映射。另外,我不认为将状态转换为因子在这里是相关的。 -
@Z.Lin,我做到了,但它创造了一个传奇,并没有解决问题。
-
我认为我分享的帖子的主要观点是很难为箱线图填充渐变颜色,并且在可视化方面没有添加新信息。
-
伙计们,放松一下,Hadleys 说不 :( Hadley Wickham @hadleywickham 1m 1 分钟前
标签: r ggplot2 gradient boxplot palette