0

I have a dataset, for example, iris, and I want to visualize the relationships between two of its covariates: Sepal.Length and Sepal.Width. It is easy to make a scatter plot:

plot(iris$Sepal.Length, iris$Sepal.Width)

However, if I want to make the plot a heat map (showing how many data points fall into each pixel), with pixels in 0.5 x 0.5, is there an easy way to plot the heat map without having to take pains in transforming the data?

Ideally I would like a solution that is easy for me to modify the width and length of the pixels, or how many pixels per row and per column for the whole plot. Also, how can I make the heat map after scale_x_log10() on x axis?

Thanks

Caprikuarius
  • 176
  • 7
  • A pixel is a fixed size in the hardware of your display. I think you just mean a general square or tile or 2D bin. I'm not sure what exaclty you mean by 0.5 x 0.5 in this case. Maybe `ggplot(iris) + geom_bin2d(aes(Sepal.Length, Sepal.Width))` would do what you want. – MrFlick Aug 22 '19 at 19:06
  • Related: https://stackoverflow.com/questions/28771018/getting-counts-on-bins-in-a-heat-map-using-r – MrFlick Aug 22 '19 at 19:07
  • Also: https://stackoverflow.com/q/38822718/4550695 – Mikko Marttila Aug 22 '19 at 19:19
  • 1
    `ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, z = 1)) + stat_summary_2d(fun = sum, binwidth = 0.5)` – d.b Aug 22 '19 at 19:37

0 Answers0