我希望常规plot()
函数中的y轴从绘图区域的底部开始,类似于hist()
函数。换句话说,我希望两个轴的零点处于同一水平。这是我的工作示例
set.seed(1)
data <- data.frame(
type = as.factor(sample(c('A', 'B', 'C'), size = 100, replace = T)),
value = rexp(100, 1/3)
)
plot(data$type)
par(new=TRUE)
plot(tapply(data$value, data$type, mean),
xaxt="n", yaxt="n", xlab="", ylab="",
xlim=c(0.55,3.45), ylim=c(0, 5), bty='n', pch=24, bg='black')
axis(4)
我尝试在yaxs = 'i'
函数中使用参数plot()
,但它将轴移动得太低。这有什么解决方案吗?
答案 0 :(得分:0)
找一个变种
在第一个情节中设置ylim
试
plot(data$type, yaxs = 'i',ylim=c(0,max(apply(data, 2, table)[[1]])))
par(new=TRUE)
plot(tapply(data$value, data$type, mean),
xaxt="n", yaxt="n", xlab="", ylab="",
xlim=c(0.55,3.45), ylim=c(0, 5), bty='n', pch=24, bg='black',yaxs = 'i')
axis(4)
axis(1,at=c(0,5)) #only for show that one lvl