Coder Social home page Coder Social logo

Comments (6)

alastairrushworth avatar alastairrushworth commented on July 22, 2024 1

Hey @sfd99 thanks for raising the issue! and sorry for the long delay in responding. Although it looks a bit strange once visualised, I think this is the expected behaviour - the histogram binning is carried out by base R's hist() function, and those bins won't necessarily center over the values when there are only a small number of unique values. For example, hist(mtcars$carb, breaks = 20) and hist(mtcars$cyl, breaks = 20) both generate images that are consistent with inspectdf.

However, I do see the problem, and I think there should be a feature to make it obvious that the histogram doesn't make much sense. I'll have a think and get back if there is an update. thanks again :)

from inspectdf.

alastairrushworth avatar alastairrushworth commented on July 22, 2024 1

thanks! I think a general solution to this is more complex than it sounds. It's not uncommon to have int columns that have very many unique values, where it wouldn't make sense to treat them as categories. Perhaps there could be a simple rule eg. fewer than 10 unique values and int --> count frequencies rather than using buckets. I'm not sure.

from inspectdf.

sfd99 avatar sfd99 commented on July 22, 2024

Hi Alastair,

Thanks for the response.

Yes,
pls do let us know
if you find a solution to this weird hist quirk.
Looking forward to it!.

Great PKG...

Best,
sfd99
San Francisco
latest Rstudio/R/Ubuntu Linux
inspectdf 0.0.11

from inspectdf.

sfd99 avatar sfd99 commented on July 22, 2024

I found a starting point
to this misalignment hist problem:

https://stackoverflow.com/questions/41486027/how-to-align-the-bars-of-a-histogram-with-the-x-axis

Take a look!...

Did this Dr, Google query:
how to align histogram bars with the corresponding values in R

One of the quoted solutions there,
when x-values are int:

This will center the hist bar
directly on top of the x-axis value:

data <- data.frame(number = c(5, 10, 11 ,12,12,12,13,15,15))
ggplot(data,aes(x = number)) + geom_histogram(binwidth = 0.5)

But there must be better R ways...
SFd99

from inspectdf.

sfd99 avatar sfd99 commented on July 22, 2024

And finally,
one last, good possible sol:

ggplot(mtcars, aes(x = factor(cyl))) +
geom_bar()

image

VIA:
https://www.guru99.com/r-bar-chart-histogram.html

from inspectdf.

sfd99 avatar sfd99 commented on July 22, 2024

Hi Alastair,

Yes, I agree.

That rule (your comment above),
could be a possible solution
to the hist alignment quirk...

If it works in a generic way,
the inspectdf PKG:: show_plot() would be the first
to solve it. :-)

thanks!
SFd99

from inspectdf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.