简体   繁体   English

条形 Plot 3 个自变量合一 plot

[英]Bar Plot with 3 independent variables in one plot

My df looks like this:我的 df 看起来像这样:

Training_Task <- c("Imag", "Imag", "Imag", "Imag", "Rephrasing", "Rephrasing", "Rephrasing", "Rephrasing")
emotionality <- c("emo", "neu", "emo", "neu", "emo", "neu", "emo", "neu")
target_type <- c("novel", "novel", "pseudo", "pseudo", "novel", "novel", "pseudo", "pseudo")
acc <- c(93, 95, 97, 98, 96, 94, 92, 90)
df <- data.frame(Training_Task, emotionality, target_type, acc)

Now I would like to create a bar plot that looks somehow like this:现在我想创建一个看起来像这样的条形 plot:

plot = ggplot(df, aes(fill =Training_Task, y=acc, x=target_type))

But I would like the IV emotionality to be added by emotional bars (emotionality = emo) being saturated and neutral bars (emotionality = neu) being pale.但我希望通过饱和的情感条(情感 = emo)和苍白的中性条(情感 = neu)来添加 IV 情感。

Is there a way to do that?有没有办法做到这一点?

You can use alpha in your aesthetic and set position to dodge :您可以在审美中使用alpha并将 position 设置为dodge

ggplot(df) +
  geom_bar(aes(fill = Training_Task, y=acc, x=target_type, alpha = emotionality), stat = 'identity', position = "dodge") +
  theme_minimal() +
  scale_alpha_discrete(range = c(1,0.4))

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM