减小R上的xaxis刻度

减小R上的xaxis刻度,r,scale,histogram,R,Scale,Histogram,我试图绘制一个柱状图,显示作为深度函数的个体数量,如下图所示: 我正在使用以下简单代码: hist(dataset,xlab="Depth",ylab="Number of individuals") 但是,我无法使用xaxis值来显示深度0和100之间的更多细节。我需要缩小比例以显示更多细节 有解决办法吗? 谢谢您可以使用基本打印或使用ggplot2执行此操作 一些样本数据: var <- sample(1:50,size=10000,replace=T) dataset <-

我试图绘制一个柱状图,显示作为深度函数的个体数量,如下图所示:

我正在使用以下简单代码:

hist(dataset,xlab="Depth",ylab="Number of individuals")
但是,我无法使用xaxis值来显示深度0和100之间的更多细节。我需要缩小比例以显示更多细节

有解决办法吗?
谢谢

您可以使用基本打印或使用
ggplot2
执行此操作

一些样本数据:

var <- sample(1:50,size=10000,replace=T)
dataset <- as.data.frame(var)
然而,这并不能解决你的问题。使用
ggplot2
可以更好地控制绘图的外观。两个例子:

ggplot(data=dataset, aes(x=var)) + 
  geom_histogram(fill = "white", color = "black", binwidth = 10) +
  scale_x_continuous("Depth", limits=c(0,60), breaks=c(0,10,20,30,40,50,60)) +
  scale_y_continuous("Number of individuals", limits=c(0,2100), breaks=c(0,400,800,1200,1600,2000)) +
  theme_bw()
其中:

其中:


使用
binwidth
参数,您可以选择所需的详细程度。

您可以通过设置特定参数来定义中断次数,例如:

dataset <- sample(1:50,size=10000,replace=T) # random data

hist(dataset,xlab="Depth",ylab="Number of individuals",breaks=100)

dataset您可能希望在此处查找其他一些见解:您是否阅读了帮助文本<代码>?历史记录
。请研究
breaks
参数,并运行示例。问题不在于breaks,而在于x轴上的数字:)
ggplot(data=dataset, aes(x=var)) + 
  geom_histogram(fill = "white", color = "black", binwidth = 5) +
  scale_x_continuous("Depth", limits=c(0,60), breaks=c(0,10,20,30,40,50,60)) +
  scale_y_continuous("Number of individuals", limits=c(0,1100), breaks=c(0,250,500,750,1000)) +
  theme_bw()
dataset <- sample(1:50,size=10000,replace=T) # random data

hist(dataset,xlab="Depth",ylab="Number of individuals",breaks=100)
dataset <- sample(1:50,size=10000,replace=T) # random data

nSep <- 5

f <- hist(dataset,xlab="Depth",ylab="Number of individuals", 
          xaxp = c(min(dataset), max(dataset), nSep))