在 R 的 barplot() 中的 Y 轴上添加增量刻度线
Add incremental tick marks on the Y-axis in barplot() for R
我创建了一个相对频率直方图,但我试图在 y 轴上添加小刻度线。当我使用 axis()
函数时,如下代码所示:
```displacement_hist <- barplot(table(dissertation$displaced)/nrow(dissertation),
axis(2, at=seq(0, 5, .25)),
main = "Global Displacement", #Give your chart a title
xlab = "Displacement by Numbers", #Label the x axis
las = 2,
cex.lab=.75,
cex.axis =.75,
cex.names = .75,
ylab = "Relative Frequency")```
它生成此图像:My histogram。当我将相同的代码与 ylim
一起使用时,如下所示:
```displacement_hist <- barplot(table(dissertation$displaced)/nrow(dissertation),
axis(2, at=seq(0, 5, .25)),
ylim = c(0, .05),
main = "Global Displacement", #Give your chart a title
xlab = "Displacement by Numbers", #Label the x axis
las = 2,
cex.lab=.75,
cex.axis =.75,
cex.names = .75,
ylab = "Relative Frequency")```
它生成此图像:My histogram2。我希望 y 轴上刻度线的值介于 0 到 .05 之间,间隔为 .0025。我怎样才能做到这一点?提前谢谢你。
这是获得所需内容的一种方法。首先,我们必须创建一些类似于您的假数据:
set.seed(42)
diss <- data.frame(displaced=sample(50, 200, replace=TRUE))
displacement_hist <- barplot(table(diss$displaced)/nrow(diss), ylim=c(0, .05),
main = "Global Displacement", xlab = "Displacement by Numbers",
las = 2, cex.lab=.75, cex.axis =.75, cex.names = .75, ylab = "Relative Frequency")
axis(2, seq(0, .05, by=.0025), labels=FALSE, tck=-.01)
我创建了一个相对频率直方图,但我试图在 y 轴上添加小刻度线。当我使用 axis()
函数时,如下代码所示:
```displacement_hist <- barplot(table(dissertation$displaced)/nrow(dissertation),
axis(2, at=seq(0, 5, .25)),
main = "Global Displacement", #Give your chart a title
xlab = "Displacement by Numbers", #Label the x axis
las = 2,
cex.lab=.75,
cex.axis =.75,
cex.names = .75,
ylab = "Relative Frequency")```
它生成此图像:My histogram。当我将相同的代码与 ylim
一起使用时,如下所示:
```displacement_hist <- barplot(table(dissertation$displaced)/nrow(dissertation),
axis(2, at=seq(0, 5, .25)),
ylim = c(0, .05),
main = "Global Displacement", #Give your chart a title
xlab = "Displacement by Numbers", #Label the x axis
las = 2,
cex.lab=.75,
cex.axis =.75,
cex.names = .75,
ylab = "Relative Frequency")```
它生成此图像:My histogram2。我希望 y 轴上刻度线的值介于 0 到 .05 之间,间隔为 .0025。我怎样才能做到这一点?提前谢谢你。
这是获得所需内容的一种方法。首先,我们必须创建一些类似于您的假数据:
set.seed(42)
diss <- data.frame(displaced=sample(50, 200, replace=TRUE))
displacement_hist <- barplot(table(diss$displaced)/nrow(diss), ylim=c(0, .05),
main = "Global Displacement", xlab = "Displacement by Numbers",
las = 2, cex.lab=.75, cex.axis =.75, cex.names = .75, ylab = "Relative Frequency")
axis(2, seq(0, .05, by=.0025), labels=FALSE, tck=-.01)