R直方图的参数
parameters of histogram with R
首先,我希望能够显示带小数的横坐标轴(例如:1.5、2.6、...),但问题是当我用我的代码显示直方图时,x 会自动显示-axis 显示整数,如下图所示(我用红色圈出了我想更改的内容):hist
我如何更改参数才能将这些整数转换为小数?
其次,我希望出现在 x 轴上的数字与我的中断向量完全对应。
有人可以帮我吗?
这是我的代码:
my_data <- transform(my_data, new = as.numeric(new/1000000))
sal_hist_default = hist(my_data$new, breaks = c(1,6.3,11.6,16.9,22.2,27.5), col = "blue", border = "black", las = 1, include.lowest=TRUE,right=FALSE, main="Salary Of best category", xlab = "salaries", ylab = "num of players",xlim = c(1,27.5), ylim = c(0,600))
你真的应该提供样本数据,但试试这个:
set.seed(42)
new <- rnorm(1000, 14, 3.5)
my_data <- data.frame(new)
sal_hist_default = hist(my_data$new, breaks = c(1, 6.3, 11.6, 16.9, 22.2, 27.5), col = "blue",
border = "black", las = 1, include.lowest=TRUE,right=FALSE, main="Salary Of best category",
xlab = "salaries", ylab = "num of players",xlim = c(1,27.5), ylim = c(0,600), xaxt="n")
axis(1, c(1, 6.3, 11.6, 16.9, 22.2, 27.5), c(1, 6.3, 11.6, 16.9, 22.2, 27.5))
首先,我希望能够显示带小数的横坐标轴(例如:1.5、2.6、...),但问题是当我用我的代码显示直方图时,x 会自动显示-axis 显示整数,如下图所示(我用红色圈出了我想更改的内容):hist 我如何更改参数才能将这些整数转换为小数?
其次,我希望出现在 x 轴上的数字与我的中断向量完全对应。
有人可以帮我吗?
这是我的代码:
my_data <- transform(my_data, new = as.numeric(new/1000000))
sal_hist_default = hist(my_data$new, breaks = c(1,6.3,11.6,16.9,22.2,27.5), col = "blue", border = "black", las = 1, include.lowest=TRUE,right=FALSE, main="Salary Of best category", xlab = "salaries", ylab = "num of players",xlim = c(1,27.5), ylim = c(0,600))
你真的应该提供样本数据,但试试这个:
set.seed(42)
new <- rnorm(1000, 14, 3.5)
my_data <- data.frame(new)
sal_hist_default = hist(my_data$new, breaks = c(1, 6.3, 11.6, 16.9, 22.2, 27.5), col = "blue",
border = "black", las = 1, include.lowest=TRUE,right=FALSE, main="Salary Of best category",
xlab = "salaries", ylab = "num of players",xlim = c(1,27.5), ylim = c(0,600), xaxt="n")
axis(1, c(1, 6.3, 11.6, 16.9, 22.2, 27.5), c(1, 6.3, 11.6, 16.9, 22.2, 27.5))