Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ggplot barplot:将每个令牌作为其自己的条_R_Ggplot2 - Fatal编程技术网

ggplot barplot:将每个令牌作为其自己的条

ggplot barplot:将每个令牌作为其自己的条,r,ggplot2,R,Ggplot2,所以,我试着制作一个如下图所示的条形图。 对于每个发言者(1、2和3),有4个标记(每个类别2个,由黄色和灰色条表示),我希望每个单独的标记显示在图片中(每个发言者2个黄色条,两个灰色条);现在,所有的代币都折叠在各自的类别下,因此每个扬声器只有两个栏,一个黄色,一个灰色。我怎样才能使4个条表示出来 以下是我正在使用的代码: ggplot(EUD, aes(x=Speaker, y=EuD, fill=Gliding)) + geom_bar(stat="identity"

所以,我试着制作一个如下图所示的条形图。

对于每个发言者(1、2和3),有4个标记(每个类别2个,由黄色和灰色条表示),我希望每个单独的标记显示在图片中(每个发言者2个黄色条,两个灰色条);现在,所有的代币都折叠在各自的类别下,因此每个扬声器只有两个栏,一个黄色,一个灰色。我怎样才能使4个条表示出来

以下是我正在使用的代码:

ggplot(EUD, aes(x=Speaker, y=EuD, fill=Gliding)) +
geom_bar(stat="identity", position=position_dodge())+
xlab("Speaker")+
ylab("EuD")+
scale_fill_manual(values = wes_palette("Darjeeling1")) +
theme(axis.text = element_text(size = 9, family="Times"))+
theme(axis.title.x = element_text(size=9, family="Times"))+
theme(axis.title.y = element_text(size=9, family="Times"))+
theme(legend.title = element_text(size=9, family="Times"),  legend.text = 
element_text(size=9, family="Times"))
谢谢

劳伦

以下是dput(EUD)的输出:


也许你正在寻找这个:

library(ggplot2)
library(dplyr)
#Code
EUD %>%
  group_by(Speaker) %>%
  mutate(Mytoken=paste0(Gliding,row_number())) %>%
  ggplot(aes(x=Speaker, y=EuD, fill=Mytoken)) +
  geom_bar(stat="identity",color='black',
           position=position_dodge(),alpha=0.5)+
  xlab("Speaker")+
  ylab("EuD")+
  scale_fill_manual(values = c('yellow','yellow','gray25','gray25')) +
  theme(legend.position = 'none',
        axis.text = element_text(size = 9, family="Times"))+
  theme(axis.title.x = element_text(size=9, family="Times"))+
  theme(axis.title.y = element_text(size=9, family="Times"))+
  theme(legend.title = element_text(size=9, family="Times"),
        legend.text = element_text(size=9, family="Times"))
输出:


Hi Lauren,请在您的控制台上使用
dput(EUD)
,复制输出,编辑您的问题并粘贴它以帮助您!
library(ggplot2)
library(dplyr)
#Code
EUD %>%
  group_by(Speaker) %>%
  mutate(Mytoken=paste0(Gliding,row_number())) %>%
  ggplot(aes(x=Speaker, y=EuD, fill=Mytoken)) +
  geom_bar(stat="identity",color='black',
           position=position_dodge(),alpha=0.5)+
  xlab("Speaker")+
  ylab("EuD")+
  scale_fill_manual(values = c('yellow','yellow','gray25','gray25')) +
  theme(legend.position = 'none',
        axis.text = element_text(size = 9, family="Times"))+
  theme(axis.title.x = element_text(size=9, family="Times"))+
  theme(axis.title.y = element_text(size=9, family="Times"))+
  theme(legend.title = element_text(size=9, family="Times"),
        legend.text = element_text(size=9, family="Times"))