2016-12-26 88 views
1

我是R中ggplot2圖形的新手。我需要在圖片中創建圖形。在R中使用ggplot2創建繪圖

enter image description here

它的靈敏度和特異性對每個規則之間的比較。我平均每個模型有20條規則。比較搜索表格中的結果是比較生成的規則的質量的最簡單方法。

我的輸入將是3列數據框:1個字符(或因子)和2個數字。

,這是我的[R版本和操作系統:

R version 3.3.1 (2016-06-21) 
OS X 10.12.2 (Sierra). 
ggplot2_2.1.0 

任何提示,將不勝感激。

+0

我回答你的問題,但下一次,你應該有一個例子數據集:d –

+0

謝謝你的答案和建議:d –

+0

沒問題,樂意幫幫我 –

回答

1

這是你如何做到這一點

library(ggplot2) 

df<- data.frame(rule = c("rule 1", "rule 2", "rule 1"), value = c(-0.8, 0.55, 0.8), qualityMeasure = c("FPR", "TPR", "TPR")) 

dat1 <- subset(df,value >= 0) 
dat2 <- subset(df,value < 0) 

ggplot() + geom_bar(data = dat2, stat = "identity", aes(x = rule, y = value, fill = qualityMeasure)) + geom_bar(data = dat1, stat = "identity", aes(x = rule, y = value, fill = qualityMeasure)) + coord_flip()