首页 > 解决方案 > 使用 dotplot (binaxis = "y") 绘图时出现 x 轴错误 - ggplot

问题描述

你能帮我理解为什么我的 x 轴看起来很奇怪并帮助我解决这个问题吗?

标签: rggplot2dplyr

解决方案


也许您正在考虑使用 geom_point 而不是 geom_dotplot ?您的轴是离散的,因为您使用了一个因子变量,但实际上您在右侧有一个空白区域。也许您可以代替使用两个数据集,在一个数据集上执行 ggplot 并使用您创建的颜色变量为正确的点着色。

   storeProfit = storeProfit %>%mutate(color = (min(totalProfit) == totalProfit | max(totalProfit) == totalProfit))
  

ggplot(data = storeProfit, aes(x = factor(STORE), y = totalProfit,fill=color)) +
  geom_dotplot(binaxis = "y", fill = "light blue")+
  labs(title = "Total softdrink profit per Store", x = "Store", y = "Total Profit (USD$)") +
  theme(axis.text.x=element_text(angle=90,hjust=1))+
scale_fill_manual(c("light blue","red")) 

这是我能想到的最好的,没有可重复的数据集


推荐阅读