我正在努力熟悉构成R的庞大宇宙.()有一个很好的函数,它似乎只是我需要的东西,但它似乎不喜欢在数据框中选择多个列.
我使用了标准的虹膜数据集,虽然它看起来很好,只选择了一个列,但它似乎不喜欢多列的选择.该示例来自参考书,但当然可能存在拼写错误.
第一版(这是有效的)
> by(iris[,2],Species,mean)
Species: setosa
[1] 3.428
------------------------------------------------------------
Species: versicolor
[1] 2.77
------------------------------------------------------------
Species: virginica
[1] 2.974
Run Code Online (Sandbox Code Playgroud)
第二个版本(这不是)
> by(iris[,2:3],Species,mean)
Species: setosa
[1] NA
------------------------------------------------------------
Species: versicolor
[1] NA
------------------------------------------------------------
Species: virginica
[1] NA
Warning messages:
1: In mean.default(data[x, , drop = FALSE], ...) :
argument is not numeric or logical: returning NA
2: In mean.default(data[x, , drop = FALSE], ...) :
argument is not numeric or logical: returning NA
3: In mean.default(data[x, , drop = FALSE], ...) …
Run Code Online (Sandbox Code Playgroud) 我试图指定ggplot2
条形图中已应用"闪避" 的列的顺序.所需的案例顺序是CC(用于控制)C2,C3和C4.然而,当绘制时,它们以C2,C3,C4,CC形式出现(不出意外,因为'C'的ASCII值高于4,我猜).
有没有办法在应用"闪避"时指定列的顺序?我已经看到了顺序颠倒的解释,但我只是想指定顺序.
代码(到目前为止)是:
GeneExp <- ggplot(genePlot, aes(x=Gene, y=Value, fill=Case) ) +
geom_bar(stat="identity", position="dodge")
Run Code Online (Sandbox Code Playgroud)