【发布时间】:2022-01-17 20:50:16
【问题描述】:
我有以下数据集:
数据:
test <- data.frame(
cluster = c("1", "2", "3","1", "2", "3","1", "2", "3",),
variable = c("age", "age", "age", "speed", "speed", "speed", "price","price","price",),
value = c(0.33,0.12,0.98,0.77,0.7,0.6,0.11,0.04,0.15))
test$variable <- factor(test$variable, levels = c("age","speed","price"))
代码
test %>%
ggplot(aes(x = cluster, y = value ,fill = variable ,group = (cluster))) +
geom_col(position = "stack", color = "black", alpha = .75) +
coord_flip()
我尝试通过变量中的值对条形图进行排序,例如“年龄”。这是我用来可视化图表的代码,我已经尝试了排序函数,但这似乎在“填充”参数。
认为问题在于,“年龄”本身只是“变量”的一个值。
应该是这样的:
是否可以使用 ggplot 显示类似的内容,还是我需要另一个包?
【问题讨论】:
-
请使用
dput()而不是图片来发布您的数据。 -
这能回答你的问题吗? Fixing the order of facets in ggplot
-
我已经链接到关于在 ggplot 中订购酒吧的常见问题解答。如果您需要更多帮助,请编辑您的问题,以复制/粘贴文本而不是图片的形式分享您的代码和示例数据。