Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何最小化r中直方图上的间距_R_Ggplot2_Histogram - Fatal编程技术网

如何最小化r中直方图上的间距

如何最小化r中直方图上的间距,r,ggplot2,histogram,R,Ggplot2,Histogram,假设我有两种数据。一个在小范围内(从0到0.5),另一个在大范围内(从4到600)。第一个称为v,第二个称为mx data<-structure(list(v = c(0.0741993337844943, 0.0469609897824665, 0.27686789382899, 0.0899877689865293, 0.0533351613571831, 0.0949535942113873, 0.132267448969788, 0.140736814439988, 0.170

假设我有两种数据。一个在小范围内(从0到0.5),另一个在大范围内(从4到600)。第一个称为
v
,第二个称为
mx

data<-structure(list(v = c(0.0741993337844943, 0.0469609897824665, 
0.27686789382899, 0.0899877689865293, 0.0533351613571831, 0.0949535942113873, 
0.132267448969788, 0.140736814439988, 0.170258755089611, 0.0012874981224646, 
0.0167425549755457), mx = c(20.2159112302004, 15.2656614271742, 
14.4361762323113, 8.87425807502441, 4.04997522826475, 34.9314254746675, 
45.699439750261, 16.0238858355385, 79.4436180395085, 598.247400459265, 
5.16677793308584)), class = "data.frame", row.names = c(NA, -11L
))

例如,
v
图上没有介于0.0和0.1之间的值。我想给这个差距增加更多的值,比如0.01,0.02。。。对于另一个图,我想添加更多的值,比如0-10-20-30…200-210

简言之,我想最小化所有具有不同范围的图的所有间隙

data<-structure(list(v = c(0.0741993337844943, 0.0469609897824665, 0.27686789382899, 0.0899877689865293, 0.0533351613571831, 0.0949535942113873,  0.132267448969788, 0.140736814439988, 0.170258755089611, 0.0012874981224646, 0.0167425549755457),
                     mx = c(20.2159112302004, 15.2656614271742, 14.4361762323113, 8.87425807502441, 4.04997522826475, 34.9314254746675, 45.699439750261, 16.0238858355385, 79.4436180395085, 598.247400459265, 5.16677793308584)),
                class = "data.frame", row.names = c(NA, -11L))


library(ggplot2)    
ggplot(data, aes(x=data$v)) + geom_histogram(bins=10)
ggplot(data, aes(x=data$mx)) + geom_histogram(bins=10)


也许:
ggplot(data,aes(x=v))+geom_直方图(binwidth=0.01)
?不确定您想要实现什么:您的
数据在图表中根本不包含任何空白值-也许
geom_density()
在视觉上更接近您想要实现的目标。您还可以添加
scale_x_log10()
为了减小间隙,请注意这可能会使轴更难理解。
data<-structure(list(v = c(0.0741993337844943, 0.0469609897824665, 0.27686789382899, 0.0899877689865293, 0.0533351613571831, 0.0949535942113873,  0.132267448969788, 0.140736814439988, 0.170258755089611, 0.0012874981224646, 0.0167425549755457),
                     mx = c(20.2159112302004, 15.2656614271742, 14.4361762323113, 8.87425807502441, 4.04997522826475, 34.9314254746675, 45.699439750261, 16.0238858355385, 79.4436180395085, 598.247400459265, 5.16677793308584)),
                class = "data.frame", row.names = c(NA, -11L))


library(ggplot2)    
ggplot(data, aes(x=data$v)) + geom_histogram(bins=10)
ggplot(data, aes(x=data$mx)) + geom_histogram(bins=10)
ggplot(data, aes(x=data$v)) + geom_histogram(binwidth=0.01)
ggplot(data, aes(x=data$mx)) + geom_histogram(binwidth=10)