b41*_*154 1 r bar-chart sweave
当我使用 时barplot,如果名称太大,我看不到条的名称。例如:
barplot(as.numeric(c(2, 4, 1, 6)), col = c("lightblue"), main="Barplot",
names.arg=c("This is bar 1...1", "This is bar 1...2",
"This is bar 1...3", "This is bar 1...4"),
xpd=TRUE, las=1, lwd=1, cex.names=0.5)
Run Code Online (Sandbox Code Playgroud)
当我使用时horiz=TRUE,我看不到左边的名字:
barplot(as.numeric(c(2, 4, 1, 6)), col = c("lightblue"), main="Barplot",
names.arg=c("This is \nbar 2...1", "This is bar 2...2",
"This is bar 2...3", "This is bar 2...4"),
xpd=TRUE, las=1, lwd=1, horiz=TRUE, space=1)
Run Code Online (Sandbox Code Playgroud)
在名称中使用换行符(例如“这是 \nbar 2...1”)或减小文本大小,例如cex.names=0.5“解决”问题,但我更愿意添加空格以使名称适合。
有没有能力改变包括情节在内的整个图形的宽度?
当horiz=FALSE(默认)时,一种选择是使用 绘制垂直于 x 轴的条形名称las=2,并将高度添加到底部边距以适应名称的长度。要为边距添加空间,请使用par(mar=c(b, l, t, r))、 其中b、l、t和r是数字,分别给出您希望底部、左侧、顶部和右侧边距的行宽/高度数。
例如:
par(mar=c(15, 3, 3, 1)) # 15 line height for bottom margin
barplot(c(2, 4, 1, 6), main="Barplot", las=2,
names.arg=c("This is my first very long name",
"This is my second very long name",
"This is my third very long name",
"This is my fourth very long name"))
Run Code Online (Sandbox Code Playgroud)
当horiz=TRUE,您可以使用las=1并在左边距中添加空间:
par(mar=c(3, 15, 3, 1))
barplot(c(2, 4, 1, 6), main="Barplot", las=1, horiz=TRUE,
names.arg=c("This is my first very long name",
"This is my second very long name",
"This is my third very long name",
"This is my fourth very long name"))
Run Code Online (Sandbox Code Playgroud)