- 已编辑
先请运行一下下面这段代码,我的问题是如何调整y轴类别标签的距离,不想用ggplot2
library(ISLR)
data(NCI60) # NCI 60 Data
library(RColorBrewer)
dat <- as.data.frame(table(NCI60$labs))
order_dat <- dat[order(dat$Freq,decreasing = TRUE),]
num <- order_dat[,2]
names(num) <- order_dat[,1]
op <- par(mar=c(4,8,2,1))
barplot(num, col = brewer.pal(12,"Set3"), axes = FALSE, border=NA, axisnames=FALSE,
horiz=TRUE,xlab="numbers",ylab="",legend.text = TRUE)
xlabs <- seq(0, 9, by = 1)
ylabs <- order_dat[,1]
axis(1, labels = xlabs, at = xlabs, las = 1) # x-axis
axis(2, labels = ylabs, at = seq(14), las = 1,lwd =1) # y-axis
par(op)
出图如下: