gpt4 book ai didi

r - 在 count=0 的情况下,如何使用 geom_bar() 去除 ggplot2 图的更宽条

转载 作者:行者123 更新时间:2023-12-04 11:31:02 25 4
gpt4 key购买 nike

<分区>

这是我的data.frame():

df <- data.frame(Round = rep(c("A", "B", "C" ),150), Group = rep(c("UP", "DOWN"),75),Task = rep(c("T1", "T2", "T3", "T4", "T5"),30), V2 = sample(c(0,1,2), 50, replace = T), V1 = sample(c(0,1,2), 50, replace = T))
dfmelt <- melt(df)

我正在尝试像这样绘制一个 facet_grid:

b <- ggplot(data=dfmelt, aes(x=value, fill=variable))
b <- b + geom_bar(stat="count", position = "dodge", width = 0.9)
b <- b + facet_grid(Group ~ Task, scales = "free")

,产生以下内容:

enter image description here

我想去掉比较宽的列,比如V1 at the position 0 of T1-UP, V1 at the position 1 of T5-DOWN and V2在T3-UP的位置0.

当我的一个变量(比方说 V1)在给定 x 位置(0,1 或 2)的 count 等于 0 并且另一个变量 (V2) 大于 0。在这种情况下,V2 条变宽以填充整个 x 位置。

我试过这个thisthis没有成功的解决方案。 有没有办法让条形具有固定宽度?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com