0

私は ggplot2 を使用してデータをプロットしています。そのおもちゃの例を以下に示します。ggplotラベルをソートし、ソートされた順序でポイントをプロットするようです (最初に a、次に b、次に c)。 c.)。

これどうやってするの?

library(ggplot2)
tmp<- data.frame(testname=c("b","b","a","a","c","c"), variable=c(40,50,40,50,40,50), value=c(0.5,0.6,0.7,0.8, 0.4, 0.8))
tmp

> tmp
  testname variable value
1        b       40   0.5
2        b       50   0.6
3        a       40   0.7
4        a       50   0.8
5        c       40   0.4
6        c       50   0.8
ggplot(tmp, aes(testname, value)) + geom_point(aes(group=variable, colour= variable), ) + theme_bw() 
4

1 に答える 1

1

最も簡単な方法は、プロットする前に因子の順序を手動で追加することです

tmp$testname <- factor(tmp$testname, levels=c("b", "a", "c"))
于 2013-07-10T14:52:34.167 に答える