【问题标题】:How to transpose or say flip the x and y axis in R [closed]如何转置或说翻转R中的x和y轴[关闭]
【发布时间】:2019-05-17 13:27:15
【问题描述】:

如果我想翻转直方图,我会怎么做。我尝试了谷歌,但找不到任何有用的东西。请帮忙。

【问题讨论】:

  • 你能给我们提供一个可重现的例子吗?如果您使用ggplot2,则可以使用coord_flip() 来执行此操作。
  • Vertical Histogram的可能重复
  • 你确定你用谷歌搜索正确吗?看这里:sthda.com/english/wiki/…

标签: r


【解决方案1】:

您可能想要的是条形图,因为直方图无法翻转。请参阅以下条形图示例:

http://www.statmethods.net/graphs/bar.html

根据需要注意最后一个绘图“翻转”轴:

par(las=2) # make label text perpendicular to axis
par(mar=c(5,8,4,2)) # increase y-axis margin.
counts <- table(mtcars$gear)
barplot(counts, main="Car Distribution", horiz=TRUE, names.arg=c("3 Gears", "4 Gears", "5   Gears"), cex.names=0.8)

它使用horiz=TRUE 选项来翻转轴。

要将直方图转换为条形图,请执行以下操作:

h <- hist(rnorm(1000))
barplot(h$counts, horiz = TRUE)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-16
    • 1970-01-01
    • 2022-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多