Histogram with “negative” logarithmic scale in R

前端 未结 4 1999
名媛妹妹
名媛妹妹 2020-12-08 12:40

I have a dataset with some outliers, such as the following

x <- rnorm(1000,0,20)
x <- c(x, 500, -500)

If we plot this on a linear x a

4条回答
  •  既然无缘
    2020-12-08 13:02

    Why suffer with ggplot2 solution? Your first plot was done with lattice histogram function, and this is where you should stay. Just apply logarithmic transformation directly within histogram function, use nint argument to specify the number of histogram bins, and type argument to choose between "count", or "density". I think that you got everything you need there, but maybe I'm missing some crucial detail of your question...

    library(lattice)
    histogram(log10(x), nint=50, type="count")
    

    enter image description here

提交回复
热议问题