gpt4 book ai didi

r - 具有小平面和相同条形尺寸(binwidth)的条形图,可选择缩小面板尺寸

转载 作者:行者123 更新时间:2023-12-02 03:40:00 27 4
gpt4 key购买 nike

我想使用条形图以类似分面的方式比较数据,但缺少数据会导致条形“宽度”不同:

enter image description here

我怎么能

  1. 确保相同的条形尺寸(“宽度”)和
  2. [很高兴] 将每个面的面板尺寸缩小到真正需要的尺寸?

PS:我不想将空数据显示为“零栏”以免浪费空间。

library(ggplot2)
data <- data.frame(product = c("Fish", "Chips", "Baguette"),
store = c("London", "London", "Paris"),
customer.satisfaction = c(0.9, 0.95, 0.8),
stringsAsFactors = TRUE)
data

ggplot(data, aes(x = product, y = customer.satisfaction)) +
geom_bar(stat = "identity", width = 0.9) +
coord_flip() +
facet_wrap( ~ store, ncol = 1, scales = "free_y")

最佳答案

也许使用分面网格的方法会令人满意:

ggplot(df, aes(x = product, y = customer.satisfaction)) +
geom_bar(stat = "identity", width = 0.9) +
coord_flip() +
facet_grid(store ~., scales = "free", space = "free")

enter image description here

关于r - 具有小平面和相同条形尺寸(binwidth)的条形图,可选择缩小面板尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48961911/

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