我正在尝试使用格子图形在条形图中绘制数据。我想按一个因素对条形图进行排序,并按另一个因素对条形图进行分组(即,按第一个因素定位,按第二个因素定位对比)。但是,我想按第一个(即位置)因素为条形着色。
在以下示例中,绘图以成对的红色和蓝色条形呈现。相反,我想要两个相邻的红色条、两个相邻的蓝色条和两个相邻的绿色条。
library(lattice)
data = runif( 6 )
facA = rep( c( "a", "b", "c" ), each = 2 )
facB = rep( c( "1", "2" ), 3 )
df = data.frame( "FactorA" = facA, "FactorB" = facB, "Data" = data )
df$FactorA = = as.factor( FactorA )
df$FactorB = = as.factor( FactorB )
test_colors = c( "red", "blue", "green" )
test_plot = barchart(FactorA ~ Data, groups = FactorB, data = df,
horizontal = TRUE, col = test_colors, origin = 0 )
plot( test_plot )
提前致谢!