【问题标题】:Using R to plot onto 1 axis value使用 R 绘制到 1 个轴值
【发布时间】:2019-01-04 21:21:24
【问题描述】:

不知道如何表达我的问题,所以这就是我想要一个快速绘图的样子,忽略可怕的轴线和边界:

这就是我的数据的样子,非常基本:

我将符号分配给我想要绿色或红色符号的字段:

status_agged$status[status_agged$current_avg > status_agged$abc_avg] <- 2
status_agged$status[status_agged$current_avg < status_agged$abc_avg] <- 6

我现在迷失了从哪里开始我的绘图功能以在 1 行上绘制所有内容。我应该能够自己解决小问题,比如网格线和颜色。

(而且我知道这不是 R 的最佳用例,但我的其他工具没有此功能)

dput 的输出(status_agged):

structure(list(category = structure(1:5, .Label = c("Activities Transition", 
"Arrival Logistics and Greetings", "Organization of Activity", 
"Schedule and Offering", "Space Adequacy"), class = "factor"), 
    CurrentAvg = c(4, 2.75, 3.86666655540466, 3.79999995231628, 
    3), ABCAvg= c(3.819841, 3.469858, 3.725926, 3.358, 3.577333
    ), PLGAvg = c(3.69721, 3.439394, 3.638, 3.306087, 3.454638
    ), status = c(2, 6, 2, 2, 6)), row.names = c(NA, -5L), class = "data.frame")

【问题讨论】:

  • 你能发布你的数据框的dplut(df) 的输出吗?由于我们必须输入数据,因此很难处理数据图像
  • 您可以将 x 值设置为常数。 ggplot(df, aes(x = "", y = Category)) + geom_point()。以内置数据为例,ggplot(iris, aes(x = '', y = Species)) + geom_point()

标签: r ggplot2


【解决方案1】:

我们可以做

status_agged$status <- as.factor(status_agged$status)
ggplot(status_agged, aes(x = "", y = category)) + 
  geom_point(aes(fill = status, color = status, shape = status), size = 10, show.legend = FALSE) +
  scale_shape_manual(values = c("6" = 25, "2" = 24)) + theme_bw() + 
  scale_fill_manual(values = c("6" = "red", "2" = "green")) +
  scale_color_manual(values = c("6" = "red", "2" = "green")) + xlab(NULL)

除了cmets中说的,我根据你的图片设置了形状24和25(它们有fillcolor美学)。

【讨论】:

  • 嗯,我收到了错误Error: Continuous value supplied to discrete scale,我尝试使用shape=as.factor(status) 设置形状,但没有运气。我需要调整什么?
  • @simplycoding,从数据定义中删除factor 给了我这个错误,但随后as.factor 修复了它。所以可能你改变了别的东西。拥有dput(status_agged) 可以解决所有问题。
  • 添加了dput(status_agged)的输出。我应该更好地措辞第一条评论 - 在收到错误后,我将shape=as.factor(status) 也添加到其他变量中,但没有运气
  • Nvm,让它以某种方式工作。不知道我做了什么不同
  • @simplycoding,查看更新。是的,它们必须是因子,因为您想使用离散量表。
猜你喜欢
  • 2021-12-30
  • 1970-01-01
  • 2016-08-25
  • 2020-07-01
  • 2015-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多