簡體   English   中英

ggplot2中的不同分組條形圖

[英]Different Grouped Bar Plot in ggplot2

在下面使用這組數據:

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

有什么辦法可以使用這些特定的數據集來制作這種條形圖?

在此處輸入圖片說明

我已經嘗試過像這樣的事情:

ggplot(jobtest, aes(x = GPU_Config, y = Seconds, fill = GPU_Config, color = GPU_Config)) + geom_bar(position = position_dodge(.908), stat = "identity")

有趣的是,將position設置為position_jitter()或position_jitterdodge()確實會開始將小節分開,但是僅執行閃避將什么也不做。

但是它們似乎不起作用。 關於分組條形圖的許多其他R帖子都略有不同,難以理解。 我絕對不是R專家。 有人可以幫忙嗎?

編輯


更多新信息曝光。 通過在CSV的末尾添加“類型”列,將每一行設置為不同的字母AI和將“填充”設置為相等的“類型”來編輯數據,但是顯然所有條形現在都是不同的顏色。 沒有辦法將它們分組為相同的顏色嗎?

新數據:

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

新代碼:

ggplot(jobtest, aes(x = GPU_Config, y = Seconds, fill = Type, color = "Black")) + geom_bar(position = position_dodge(), stat = "identity")

在此處輸入圖片說明

像這樣嗎

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

在此處輸入圖片說明

如果您不希望小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')
  )

在此處輸入圖片說明

這是您要找的東西嗎?

    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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM