在R中绘制字符向量

时间:2013-05-03 17:34:22

标签: r

我有以下两个字符向量,这可能是一种有意义的绘制值的方法

Observed_Value          Simulated_Value

   IP                      BP
   SP                      IP
   BP                      SP
   IP                      IP

1 个答案:

答案 0 :(得分:3)

好吧,也许您对热图感兴趣,热图会显示特定组合出现的频率:

library("plyr")
library("ggplot2")
df <- data.frame(
  Observed  = sample(rep( c("IP", "SP", "BP"), 100 )),
  Simulated = sample(rep( c("IP", "SP", "BP"), 100 ))
)
counts <- ddply( df, c("Observed", "Simulated"), nrow )
names(counts)[3] <- "sum"
ggplot( counts, aes( x = Observed, y = Simulated, fill = sum ) ) + geom_tile()

enter image description here