2
votes

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?:

enter image description here

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.

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. I'm not an R expert by any means. 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, A-I, and setting Fill to equal "Type" works, however obviously all the bars are now different colors. 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")

enter image description here

2
Please post your updated code. If you don't want color, remove the fill = GPU_Config - Tung
@thecatalyst new code and data posted. I mean can I group Each of the Config bar sections into the same color. Like have 0_1_2_3 bars all be black and 02_13 all be red for example (with outlines). - antong
@thecatalyst If I set fill to be GPU_Config, or remove fill = GPU_Config, this type of graph as shown above DOES NOT appear (style wise/separation like above), which is why I'm wondering if its possible. - antong

2 Answers

4
votes

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')

enter image description here

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

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')
  )

enter image description here

1
votes

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)

Result