简体   繁体   English

R error.bars获取所有x轴标签

[英]R error.bars get all x-axis labels

I am trying to plot means with standard deviations using the error.bars and it works quite good. 我正在尝试使用error.bars绘制具有标准差的均值,并且效果很好。 I know I could also use the ggplot approach but I could not implement that for my data... 我知道我也可以使用ggplot方法,但无法为我的数据实现该方法...

So far so good, the problem that I ran into now, is that not all variables on the x-axis are printed, in fact only every second or so. 到目前为止,我遇到的问题是,并不是x轴上的所有变量都被打印出来,实际上每秒钟才打印一次。

In boxplot, I could fix this with the command, names, las=2 . 在箱线图中,我可以使用命令names, las=2来解决此问题。 Is there something similar for the error.bars function? error.bars函数是否有类似的东西? I could not find anything in the manual. 我在手册中找不到任何内容。

Here's the code I am using: 这是我正在使用的代码:

psych:::error.bars(orderedcols,sd=TRUE,add=TRUE,arrow.len=0.05,bars=TRUE, xlab="Adjectives", ylab="Mean Intensity", main="Mean Intensities and Standard Deviations")

EDIT: 编辑:

dput(orderedcols) structure(list(brilliant = c(50, 82, 80, 12, 80, 80, 85, 72, 80, 85, 65, 100, 90, 97, 85, 95, 100, 100), ingenious = c(75, 70, 50, 79, 85, 80, 100, 50, 95, 90, 50, 100, 100, 1, 80, 83, 83, 100), intelligent = c(40, 70, 45, 87, 75, 60, 80, 42, 86, 80, 29, 100, 50, 45, 61, 77, 40, 90), bright = c(20, 60, 40, 58, 65, 50, 75, 40, 77, 55, 50, 58, 50, 56, 76, 83, 30, 75), smart = c(30, 62, 25, 47, 45, 50, 50, 32, 54, 75, 27, 81, 70, 69, 40, 85, 29, 80), brainy = c(60, 66, 20, 52, 70, 60, 50, 20, 66, 35, 31, -9, -10, 44, 78, 91, 50, 70), foolish = c(-15, -35, -20, -44, -30, -10, -20, -10, -32, -25, -27, -23, -10, -15, -25, 43, -36, -10), daft = c(-10, -60, -30, -14, -20, -10, -77, 0, -90, -20, -36, -61, 10, 0, -33, -100, -21, -50 ), dim = c(-35, -62, -20, 8, -80, -30, -35, -24, -60, -35, -34, -9, -100, -34, -83, -71, -27, -20), dumb = c(-25, -50, -60, -37, -40, -30, -25, -29, -76, -75, -78, -37, 0, -30, -39, -91, -38, -10), mindless = c(-50, -55, -60, -12, -30, -50, -25, 0, dput(orderedcols)结构(list(brilliant = c(50,82,80,12,80,80,85,72,80,85,65,100,90,97,85,95,100,100),巧妙= c(75,70,50,79,85,80,100,50,95,90,50,100,100,1,80,83,83,100),智能= c(40,70,45, 87,75,60,80,42,86,80,29,100,50,45,61,77,40,90),亮= c(20,60,40,58,65,50,75,40 ,77,55,50,58,50,56,76,83,30,75),smart = c(30,62,25,47,45,50,50,32,54,75,27,81, 70,69,40,85,29,80),头脑= c(60,66,20,52,70,60,50,20,66,35,31,-9,-10,44,78,91 ,50,70),愚蠢= c(-15,-35,-20,-44,-30,-10,-20,-10,-32,-25,-27,-23,-10,- 15,-25,43,-36,-10),daft = c(-10,-60,-30,-14,-20,-10,-77,0,-90,-20,-36, -61,10,0,-33,-100,-21,-50),dim = c(-35,-62,-20,8,-80,-30,-35,-24,-60, -35,-34,-9,-100,-34,-83,-71,-27,-20),哑= c(-25,-50,-60,-37,-40,-30, -25,-29,-76,-75,-78,-37,0,-30,-39,-91,-38,-10),没头脑= c(-50,-55,-60,- 12,-30,-50,-25、0, -62, -50, -100, -100, 0, -6, -39, -52, -59, -25), inane = c(-20, -80, -30, -6, -35, -30, -90, -25, -50, -50, -38, -100, -75, -25, -12, -100, -22, -10), stupid = c(-25, -80, -30, -75, -50, -40, -80, -28, -37, -75, -41, -50, -11, -100, -51, -91, -36, -15), dimwitted = c(-50, -77, -20, -59, -40, -60, -66, -77, -45, -25, -32, -77, -100, -46, -74, -89, -39, -30), idiotic = c(-60, -91, -50, -26, -60, -50, -83, -41, -58, -80, 30, -86, -100, -46, -91, -89, -60, -40), moronic = c(-90, -87, -40, -19, -65, -60, -90, -85, -78, -75, -59, -100, -80, -22, -71, -95, -65, -15), brainless = c(-75, -85, -80, -55, -20, -100, -90, -35, -85, -90, -31, -100, -90, -73, -31, -63, -100, -95), imbecilic = c(-100, -95, -75, 31, -50, -75, -90, -100, -72, -85, -63, -98, -100, -33, -92, -90, -74, -100)), .Names = c("brilliant", "ingenious", "intelligent", "bright", "smart", "brainy", "foolish", "daft", "dim", "dumb", "mindless", "inane", "stupid", "dimwitted", "idiotic", "moronic", "brainless", "imbecilic"), class = -62,-50,-100,-100,0,-6,-39,-52,-59,-25),inane = c(-20,-80,-30,-6,-35,- 30,-90,-25,-50,-50,-38,-100,-75,-25,-12,-100,-22,-10),愚蠢= c(-25,-80,- 30,-75,-50,-40,-80,-28,-37,-75,-41,-50,-11,-100,-51,-91,-36,-15),昏暗= c(-50,-77,-20,-59,-40,-60,-66,-77,-45,-25,-32,-77,-100,-46,-74,-89, -39,-30),idiotic = c(-60,-91,-50,-26,-60,-50,-83,-41,-58,-80,30,-86,-100,- 46,-91,-89,-60,-40),moronic = c(-90,-87,-40,-19,-65,-60,-90,-85,-78,-75,- 59,-100,-80,-22,-71,-95,-65,-15),无脑= c(-75,-85,-80,-55,-20,-100,-90,- 35,-85,-90,-31,-100,-90,-73,-31,-63,-100,-95),不确定= c(-100,-95,-75,31,-50 ,-75,-90,-100,-72,-85,-63,-98,-100,-33,-92,-90,-74,-100)),.names = c(“ brilliant” ,“聪明”,“聪明”,“聪明”,“聪明”,“聪明”,“愚蠢”,“愚蠢”,“昏昏欲睡”,“笨拙”,“没头脑”,“无聊”,“愚蠢”,“ dimwitted”,“ idiotic”,“ moronic”,“ brainless”,“ imbecilic”),类= "data.frame", row.names = c(2L, 4L, 5L, 6L, 7L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L)) 11 72 50 42 40 32 20 -10 0 -24 -29 0 -25 -28 -77 -41 -85 -35 -100 12 80 95 86 77 54 66 -32 -90 -60 -76 -62 -50 -37 -45 -58 -78 -85 -72 13 85 90 80 55 75 35 -25 -20 -35 -75 -50 -50 -75 -25 -80 -75 -90 -85 14 65 50 29 50 27 31 -27 -36 -34 -78 -100 -38 -41 -32 30 -59 -31 -63 15 100 100 100 58 81 -9 -23 -61 -9 -37 -100 -100 -50 -77 -86 -100 -100 -98 16 90 100 50 50 70 -10 -10 10 -100 0 0 -75 -11 -100 -100 -80 -90 -100 17 97 1 45 56 69 44 -15 0 -34 -30 -6 -25 -100 -46 -46 -22 -73 -33 18 85 80 61 76 40 78 -25 -33 -83 -39 -39 -12 -51 -74 -91 -71 -31 -92 19 95 83 77 83 85 91 43 -100 -71 -91 -52 -100 -91 -89 -89 -95 -63 -90 20 100 83 40 30 29 50 -36 -21 -27 -38 -59 -22 -36 -39 -60 -65 -100 -74 21 100 100 90 75 80 70 -10 -50 -20 -10 -25 -10 -15 -30 -40 -15 -95 -100 “数据框”,行名称= c(2L,4L,5L,6L,7L,9L,10L,11L,12L,13L,14L,15L,16L,17L,18L,19L,20L,21L))11 72 50 42 40 32 20 -10 0 -24 -29 0 -25 -28 -77 -41 -85 -35 -100 12 80 95 86 77 54 66 -32 -90 -60 -76 -62 -50 -37- 45 -58 -78 -85 -72 13 85 90 80 55 75 35 -25 -20 -35 -75 -50 -50 -75 -25 -80 -75 -90 -85 14 65 50 29 50 27 31 -27- 36 -34 -78 -100 -38 -41 -32 30 -59 -31 -63 15100100100 58 81 -9 -23 -61 -9 -37 -100 -100 -50 -77 -86 -100 -100 -98 16 90 100 50 50 70 -10 -10 10 -100 0 0 -75 -11 -100 -100 -80 -90 -100 17 97 1 45 56 69 44 -15 0 -34 -30 -6 -25- 100 -46 -46 -22 -73 -33 18 85 80 61 76 40 78 -25 -33 -83 -39 -39 -12 -51 -74 -91 -71 -31 -92 19 95 83 77 83 85 91 43 -100 -71 -91 -52 -100 -91 -89 -89 -95 -63 -90 20100 83 40 30 29 50 -36 -21 -27 -38 -59 -22 -36 -39 -60 -65- 100 -74 21 100 100 90 75 80 70 -10 -50 -20 -10 -25 -10 -15 -30 -40 -15 -95 -100

PS can't add a photo, have too little reputation.. PS无法添加照片,信誉太低..

It's actually pretty easy, I think: all you have to do is set the las graphical parameter before you run the error.bars command: 我认为这实际上很简单:您要做的就是在运行error.bars命令之前设置las图形参数:

par(las=2)
error.bars(orderedcols,sd=TRUE,add=TRUE,arrow.len=0.05,bars=TRUE,
           xlab="Adjectives", ylab="Mean Intensity",
           main="Mean Intensities and Standard Deviations")

A ggplot2 solution (you could rotate the labels for this one too -- search on StackOverflow for how to do it -- but I chose to rotate the whole plot instead) ggplot2解决方案(您也可以旋转该标签-在StackOverflow上搜索操作方法-但我选择旋转整个图)

library("reshape2")
library("ggplot2")
theme_set(theme_bw())
ggplot(melt(orderedcols),aes(x=variable,y=value))+
    stat_summary(geom="bar",fun.y=mean,position="identity",fill="gray")+
    stat_summary(geom="errorbar",width=0.2,
                 fun.data=function(x) { data.frame(y=mean(x), 
                     ymin=mean(x)-sd(x),ymax=mean(x)+sd(x)) })+
    coord_flip()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM