densityPlot和geom_density之间的差异

时间:2019-02-06 15:39:50

标签: r ggplot2 density-plot

我正在使用geom_density和基数R的densityPlot绘制相同的数据:

head(df)
  min_dist iteration
     <dbl> <fct>    
1   -79277 1        
2   -68987 1        
3   -98661 1        
4   -98145 1        
5  -222408 1        
6  -217409 1  

geom_density

ggplot(df) + geom_density(aes(min_dist)) + xlim(c(-1e4, 1e4)) + geom_rug(aes(min_dist))

enter image description here

densityPlot

densityPlot(df$min_dist, xlim = c(-1e4, 1e4))

enter image description here

它们完全不同!

I was under the impression that geom_density was a wrapper for stat_density

这仅仅是不同的adjust值的问题吗?

df <- structure(list(min_dist = c(-79277, -68987, -98661, -98145, -222408, 
-217409, -10759, -10363, 48034, 48525, 617038, 617069, -19656, 
-17396, -479, -333, -48721, -47691, -19761, 380, 31429, 33953, 
-9220, -61971, -609, -560, 6228, 13082, -217137, -216639, 99268, 
102365, -119574, -53795, -329407, -111401, 1018733, -559898, 
-1346, -15, -71577, -2883, 19490, -12321, -12240, -8470, -29804, 
28724, 40673, -57818, -41421, -39126, 136783, 165727, -52989, 
-51058, 58995, -12226, 8057, 44217, 13280, 16828, -80410, 11324, 
975, 2630, 14250, 17108, -29341, -27033, -79277, -68987, -98661, 
-98145, -222408, -217409, -10759, -10363, 48034, 48525, 617038, 
617069, -19656, -17396, -479, -333, -48721, -47691, -19761, 380, 
31429, 33953, -9220, -61971, -609, -560, 6228, 13082, -217137, 
-216639, 99268, 102365, -119574, -53795, -329407, -111401, 1018733, 
-559898, -1346, -15, -71577, -2883, 19490, -12321, -12240, -8470, 
-29804, 28724, 40673, -57818, -41421, -39126, 136783, 165727, 
-52989, -51058, 58995, -12226, 8057, 44217, 13280, 16828, -80410, 
11324, 975, 2630, 14250, 17108, -29341, -27033), iteration = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("1", 
"2"), class = "factor")), row.names = c(NA, -140L), class = c("tbl_df", 
"tbl", "data.frame"))

0 个答案:

没有答案