R:在boxplot中更改y轴缩放

时间:2016-03-04 10:56:16

标签: r

我使用R来创建一些箱图。

这是我的代码:

fps_error <- c(0.033872847, 0.041710742,0.023839866,0.017763328,0.044510719,0.016390502,0.056766647,0.101326807,0.013990558,0.014848592)
fps_error = fps_error *100
fps_qp_error <-c(1.631578947,  2.263157895, 1.45,   1.2,    2.388888889,    1.05,   1.764705882,    4.642857143,    0.95,   1.047619048)
bit_error <- c(0.113818414,0.17059614,  0.110048539,    0.030207725,    0.157858064,    0.031467476,    0.258009778,    0.220182593,    0,  0.030935528)
bit_error = bit_error *100
bit_qp_error <-c(0.65, 0.80952381,  0.523809524,    0.142857143,    0.904761905,    0.142857143,    1.473684211,    1.047619048,    0,  0.19047619)
ssim_error <-c(0.012973075,  0.006374072,   0.003292312,    0.003139452,    0.009791549,0.008385301,    0.003566528,    0.00986248, 0.003586361,    0.003680912)
ssim_qp_error <-c(3.476190476, 0.944444444, 0.7,    0.65,   2.095238095,    1.470588235,    0.75,   1.529411765,    0.736842105,    0.8)
ssim_qp_error = ssim_qp_error *100

all_errors = cbind(fps_error, bit_error, ssim_error)
modes = cbind(rep("FPS error",10), rep("Bitrate error",10), rep("SSIM error",10))

journal_linear_data <-data.frame(fps_error, fps_qp_error,bit_error,bit_qp_error,ssim_error,ssim_qp_error )

bp = boxplot(all_errors~modes, data=journal_linear_data, main="Percentage error per mode for B2", xlab="Mode", ylab="% error")

这是结果图像。 enter image description here

我想更改y轴刻度以显示所有箱子的公平性。例如。对于SSIM错误,我无法看到错误。

1 个答案:

答案 0 :(得分:1)

journal_linear_data <-data.frame(fps_error, fps_qp_error,bit_error,bit_qp_error,ssim_error,ssim_qp_error )

yvars <- c("fps_error","bit_error","ssim_error")

graphics.off()

op <- par(mfrow = c(1, 3), #matrix of plots
          oma = c(0,0,3,0))   #outer margins

for (i in 1:3) {boxplot(journal_linear_data[,yvars[i]], xlab=yvars[i], ylab="% error")}

par(op)

mtext(text="Percentage error per mode for B2",side=3, line=1.5, font=2, cex=2, col='black')

See plot here