更改 R 中条形图上的条形宽度

问题描述 投票:0回答:1

如何更改条形图上条形的宽度,使其看起来像第二张图一样细?我应该使用 geom_bar(width = )??忽略图片中的误差线。示例数据在绘图上没有误差线。

#add libraries
library(ggpattern)
library(dplyr)
library(tidyverse)
# create a dataset 
specie <- c(rep("sorgho" , 3) , rep("poacee" , 3) , rep("banana" , 3) , rep("triticum" , 3) )
condition <- rep(c("normal" , "stress" , "Nitrogen") , 4)
value <- abs(rnorm(12 , 0 , 15))
data <- data.frame(specie,condition,value)

df <- data
df[3]
df

# Grouped
set.seed(123)
df
ggplot(df, aes(fill = condition, y = value, x = specie)) +
  scale_fill_manual(
    "Position",
    values = c("black", "white", "lightgrey")
  ) +
  scale_pattern_manual(
    "Position",
    values = c("none", "stripe", "none")
  ) +
  geom_col_pattern(
    aes(pattern = condition),
    position = "dodge",
    pattern_angle = 45,
    pattern_density = .1,
    pattern_spacing = .04,
    pattern_fill = "black",
    color = "black"
  ) +
  theme_classic() +
  theme(
    text = element_text(size = 16, family = "sans"),
    plot.title = element_text(hjust = 0.5, size = 20, face = "bold")
  ) +
  labs(
    x = "Lakes", y = "Total Plankton Abundance (x106 cells/L)" )
r bar-chart rstudio
1个回答
1
投票
  geom_col_pattern(
    aes(pattern = condition),
    position = position_dodge(width = 0.6),  # group width
    width = 0.4,                             # bar width
    pattern_angle = 45,
    pattern_density = .1,
    pattern_spacing = .04,
    pattern_fill = "black",
    color = "black",
  ) +

© www.soinside.com 2019 - 2024. All rights reserved.