2015-03-31 15 views
1

由於要求苛刻的最終用戶,我需要了解geom_box繪圖上的晶須線條是否可以以不同於盒子本身的顏色或打字方式進行打印?如何在geom_box繪圖上自定義晶須線,與盒子本身的線條不同

剛剛考慮過boxplot with colored and dotted lines,我創建了一個最簡單的例子。

year <- rep("2014", 10) 
total <- c(seq(55, 90, 5), 100, 40) 
df <- data.frame(year = as.factor(year), total = total) 

ggplot(df, aes(x=factor(year), y=total)) + 
    geom_boxplot(linetype = "dotted", color = "red") + 
    theme_bw() 

下面的圖可以有綠色的鬍鬚,保持紅色的盒子,或堅實的鬍鬚保持虛線框?

enter image description here

這太問題告訴我們,基礎R許可證晶須在線定製濟。 bxp has several parameters

編輯後評論: 我沒有發現這個問題user20650親切地指出。這是它的答案 - 兩次繪製箱形圖。

ggplot(df, aes(x=factor(year), y=total)) + 
    geom_boxplot(linetype = "dotted", color = "red") + 
    geom_boxplot(aes(ymin=..lower.., ymax=..upper..)) + 
    theme_bw() 
+0

如果這確實回答你的問題,你應該把它作爲答案提交,而不是編輯到你的問題。 – Gregor 2015-03-31 17:19:37

+0

@格雷戈,謝謝。我從未使用過自我回答的方法。奇怪的是,user20650的評論被刪除。我想上傳評論。 – lawyeR 2015-03-31 17:40:36

回答

2

編輯後評論:我沒有發現這個問題user20650親切地指出。這是它的答案 - 兩次繪製箱形圖。

ggplot(df, aes(x=factor(year), y=total)) + 
    geom_boxplot(linetype = "dotted", color = "red") + 
    geom_boxplot(aes(ymin=..lower.., ymax=..upper..)) + 
    theme_bw() 
相關問題