[英]Different Grouped Bar Plot in ggplot2
Using this set of data below: 在下面使用这组数据:
GPU_Config,Job_Num,File_Amount,Seconds
0_1_2_3,4,1400,44015.833
0_1_2_3,8,1400,35509
0_1_2_3,12,1400,40544.75
02_13,2,1400,50209.5
02_13,4,1400,39379
02_13,6,1400,39507
02_13,8,1400,39871
02_13,10,1400,42823.75
02_13,12,1400,46727
Is there any way to make a bar graph of this sort with this specific set of data?: 有什么办法可以使用这些特定的数据集来制作这种条形图?
I've tried things like this: 我已经尝试过像这样的事情:
ggplot(jobtest, aes(x = GPU_Config, y = Seconds, fill = GPU_Config, color = GPU_Config)) + geom_bar(position = position_dodge(.908), stat = "identity")
Interestingly enough, setting position to position_jitter() or position_jitterdodge() does start to separate the bars a little bit, however just doing dodge does nothing at all. 有趣的是,将position设置为position_jitter()或position_jitterdodge()确实会开始将小节分开,但是仅执行闪避将什么也不做。
But they don't seem to work. 但是它们似乎不起作用。 A lot of other R posts concerning grouping bar graphs are all slightly different and difficult to understand.
关于分组条形图的许多其他R帖子都略有不同,难以理解。 I'm not an R expert by any means.
我绝对不是R专家。 Can someone please help?
有人可以帮忙吗?
EDIT 编辑
More new information come to light. 更多新信息曝光。 Editing the data by adding a "Type" Column at the end of the CSV, setting each row to be a different letter, AI, and setting Fill to equal "Type" works, however obviously all the bars are now different colors.
通过在CSV的末尾添加“类型”列,将每一行设置为不同的字母AI和将“填充”设置为相等的“类型”来编辑数据,但是显然所有条形现在都是不同的颜色。 Is there no way to group them in the same color?
没有办法将它们分组为相同的颜色吗?
New Data: 新数据:
GPU_Config,Job_Num,Tiff_Amount,Seconds,Type
0_1_2_3,4,1400,44015.833,a
0_1_2_3,8,1400,35509,b
0_1_2_3,12,1400,40544.75,c
02_13,2,1400,50209.5,d
02_13,4,1400,39379,e
02_13,6,1400,39507,f
02_13,8,1400,39871,g
02_13,10,1400,42823.75,h
02_13,12,1400,46727,i
New Code: 新代码:
ggplot(jobtest, aes(x = GPU_Config, y = Seconds, fill = Type, color = "Black")) + geom_bar(position = position_dodge(), stat = "identity")
Something like this? 像这样吗
text <-
"GPU_Config,Job_Num,File_Amount,Seconds
0_1_2_3,4,1400,44015.833
0_1_2_3,8,1400,35509
0_1_2_3,12,1400,40544.75
02_13,2,1400,50209.5
02_13,4,1400,39379
02_13,6,1400,39507
02_13,8,1400,39871
02_13,10,1400,42823.75
02_13,12,1400,46727"
df <- read.table(textConnection(text), sep = ",", header = TRUE)
df$type <- as.factor(1:nrow(df))
library(ggplot2)
ggplot(df) +
geom_bar(aes(x = type, y = Seconds, fill = GPU_Config),
stat = "identity", position = "dodge") +
facet_wrap(~ GPU_Config, scales = 'free_x')
If you don't want the faceting separation/want the GPU_config
on the X-axis you can hide the color guide and manually specify the colors 如果您不希望小
GPU_config
分离/想在X轴上使用GPU_config
,则可以隐藏颜色指南并手动指定颜色
ggplot(df) +
geom_bar(aes(x = GPU_Config, y = Seconds, fill = type),
colour = 'black', stat = "identity", position = "dodge") +
scale_fill_manual(guide = FALSE,
values=c("red", "red", "red",
'blue', 'blue', 'blue', 'blue', 'blue', 'blue')
)
Is this what you're looking for? 这是您要找的东西吗?
txt <- "GPU_Config,Job_Num,File_Amount,Seconds
0_1_2_3,4,1400,44015.833
0_1_2_3,8,1400,35509
0_1_2_3,12,1400,40544.75
02_13,2,1400,50209.5
02_13,4,1400,39379
02_13,6,1400,39507
02_13,8,1400,39871
02_13,10,1400,42823.75
02_13,12,1400,46727"
df1 <- read.table(textConnection(txt), sep = ",", header = TRUE)
library(ggplot2)
g + geom_bar(aes(fill = Job_Num), stat = "identity", position = "dodge") +
theme_bw() +
facet_grid( . ~ GPU_Config)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.