ggstance :: geom_barh没有翻转轴?

时间:2018-01-31 13:54:33

标签: r ggplot2

为更多普通观众发布this

请考虑以下事项:

ggplot2::ggplot(ggplot2::mpg, ggplot2::aes(class)) + ggplot2::geom_bar()

这会产生 rplot

然而

ggplot2::ggplot(ggplot2::mpg, ggplot2::aes(class)) + ggstance::geom_barh()

产生(破碎!?) rplot01 我在哪里弄错了?

3 个答案:

答案 0 :(得分:1)

使用以下Private Sub Form_ComboBox_AfterUpdate() Adjust_Box (Me.Data_Subject_Categories) End Sub Private Function Adjust_Box(ctl) ctl.Height = 300 End Function

ctl.Height = 300

然后绘制如下:

stat

enter image description here

编辑:实际上这个统计数据也是在stat_counth <- function(mapping = NULL, data = NULL, geom = "fillbar", position = "stack", ..., width = NULL, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) { params <- list( na.rm = na.rm, width = width, ... ) if (!is.null(params$y)) { stop("stat_count() must not be used with a y aesthetic.", call. = FALSE) } layer( data = data, mapping = mapping, stat = StatCounth, geom = geom, position = position, show.legend = show.legend, inherit.aes = inherit.aes, params = params ) } #' @rdname ggplot2-ggproto #' @format NULL #' @usage NULL #' @export #' @include stat-.r StatCounth <- ggproto("StatCounth", Stat, required_aes = "y", default_aes = aes(x = calc(count), weight = 1), setup_params = function(data, params) { if (!is.null(data$y)) { stop("stat_counth() must not be used with a x aesthetic.", call. = FALSE) } params }, compute_group = function(self, data, scales, width = NULL) { y <- data$y weight <- data$weight %||% rep(1, length(y)) width <- width %||% (resolution(y) * 0.9) count <- as.numeric(tapply(weight, y, sum, na.rm = TRUE)) count[is.na(count)] <- 0 data.frame( count = count, prop = count / sum(abs(count)), x = sort(unique(y)), width = width ) } ) 中实现的,似乎只是忘了将其设为默认值。

这也有效:

ggplot2::ggplot(ggplot2::mpg, ggplot2::aes(y = class)) + ggstance::geom_barh(stat = "counth")

答案 1 :(得分:0)

如果您只是试图翻转轴,可以使用以下内容:

ggplot(mpg, aes(class)) + geom_bar() + coord_flip()

答案 2 :(得分:0)

我认为这是ggstance::geom_barh的问题。

请记住,ggstance,你必须以自然的顺序提供美学。 geom_barh只会翻转geom ;它不会像coord_flip()那样翻转轴。为了您的示例,您必须这样做:

ggplot(mpg, (aes(y = class) +
  geom_barh()

然而,这会产生错误:

Error: stat_count() must not be used with a y aesthetic.