问题描述
我在按降序排列躲避条形图时遇到问题。数据集包含城市和这些城市中特定物品的价格(例如出租车、饮料、晚餐等) - 数据集可在此处找到:https://data.world/makeovermonday/2018w48
正则表达式:
City <- c("Mexico City","Prague","Moscow","Mexico City","Moscow")
Category <- c("Date Night","Date Night","Party Night","Party Night")
TotalCost <- c(84.82,86.52,20.35,46.29,19,26.56)
CostNightPrepared <- data.frame(City,Category,TotalCost)
我修改了数据集,只显示City
、Category
(夜间外出类型)和TotalCost
(每个城市每个类别的总价格):
CostNightPrepared <- CostNight %>%
group_by(City,Category) %>%
summarize(TotalCost = sum(Cost,na.rm = TRUE))%>%
arrange(Category,TotalCost)
要可视化数据集:
ggplot(CostNightPrepared,aes(TotalCost,fct_rev(fct_reorder(City,TotalCost)),fill=Category)) +
geom_bar(stat="identity",position = position_dodge(width = 0.5))
如您所见,我使用了 fct_rev
和 fct_reorder()
,但输出仍然是这样的:
如何按降序排列“派对之夜”类别的闪避(重叠)条形图?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)