Live data from Hacker News

How to make any plot in ggplot2

r-statistics.co

1–10 of 11 posts

Re: How to make any plot in ggplot2

#2
This is a pretty effective guide for the custom features that ggplot2 excels at, namely faceting. That being said, optimizing the chart requires a few more steps in each case, especially when working with real world data.

For those who want a step-by-step guide on plotting with ggplot2, I wrote a tutorial that has been well-liked with an emphasis on making pretty charts: http://minimaxir.com/2015/02/ggplot-tutorial/

Yesterday, I also pushed a screencast working explicitly with R and ggplot2, with an emphasis on processing/organizing data for charting in ggplot2: http://minimaxir.com/2015/12/lets-code-1/

TL;DR R/ggplot2 can be very fussy, but when it isn't, it's magical.

Re: How to make any plot in ggplot2

#4
It seems, as long as "Any plot" means either a scatter, or bar chart (not even a continuous histogram).

Also:

"There are 3 ways to change the X and Y axis limits. ....Warning: Items 2 and 3 will delete the datapoints that lie outisde the limit from the data itself. So, if you add any smoothing line line and such, the outcome will be distorted"

So, is this a graphics module, or a fitting module, or a data manipulation module? It seems to do all three, depending on which functions you use to "Change the axis limits".

Edit: Probably the best "How to do everything" page I've seen is for python's matplotlib's gallery page: http://matplotlib.org/gallery.html - there is rarely not an example showing exactly what I want to do.

Re: How to make any plot in ggplot2

#5
post #4

It seems, as long as "Any plot" means either a scatter, or bar chart (not even a continuous histogram). Also: "There are 3 ways to change the X and Y axis limits. ....Warning: Items 2 and 3 will delete the datapoints that lie outisde the limit from the data itself. So, if you add any smoothing line line and such, the outcome will be distorted" So, is this a graphics module, or a fitting module, or a data manipulation…

ggplot2 is a graphics module, but has shortcuts for common chart applications without having to write the code itself, such as smoothing trend lines.

The ggplot2 docs are the best source for determining the scope of the package: http://docs.ggplot2.org/current/

Re: How to make any plot in ggplot2

#6

This is a pretty effective guide for the custom features that ggplot2 excels at, namely faceting. That being said, optimizing the chart requires a few more steps in each case, especially when working with real world data. For those who want a step-by-step guide on plotting with ggplot2, I wrote a tutorial that has been well-liked with an emphasis on making pretty charts: http://minimaxir.com/2015/02/ggplot-tutorial/…

In your tutorial you recommend rendering charts on OS X in order to get proper antialiasing. Isn't it easier to render to a vector format and then batch rasterize outside R with e.g. ImageMagick? Or even better, just use the vector format?

Re: How to make any plot in ggplot2

#7

This is a pretty effective guide for the custom features that ggplot2 excels at, namely faceting. That being said, optimizing the chart requires a few more steps in each case, especially when working with real world data. For those who want a step-by-step guide on plotting with ggplot2, I wrote a tutorial that has been well-liked with an emphasis on making pretty charts: http://minimaxir.com/2015/02/ggplot-tutorial/…

In your tutorial you recommend rendering charts on OS X in order to get proper antialiasing. Isn't it easier to render to a vector format and then batch rasterize outside R with e.g. ImageMagick? Or even better, just use the vector format?

That workflow is neither the most user-friendly nor the most web-friendly.

SVGs don't have the same flexibility and compatibility as PNGs yet, unfortunately.

Re: How to make any plot in ggplot2

#8
post #4

It seems, as long as "Any plot" means either a scatter, or bar chart (not even a continuous histogram). Also: "There are 3 ways to change the X and Y axis limits. ....Warning: Items 2 and 3 will delete the datapoints that lie outisde the limit from the data itself. So, if you add any smoothing line line and such, the outcome will be distorted" So, is this a graphics module, or a fitting module, or a data manipulation…

Have you tried svglite? It produces pretty decent svgs for web use.

Re: How to make any plot in ggplot2

#9
post #4

It seems, as long as "Any plot" means either a scatter, or bar chart (not even a continuous histogram). Also: "There are 3 ways to change the X and Y axis limits. ....Warning: Items 2 and 3 will delete the datapoints that lie outisde the limit from the data itself. So, if you add any smoothing line line and such, the outcome will be distorted" So, is this a graphics module, or a fitting module, or a data manipulation…

It's part of a suite of data packages for doing analysis, which encompasses visualization, data manipulation, and modeling.

Re: How to make any plot in ggplot2

#10
post #4

It seems, as long as "Any plot" means either a scatter, or bar chart (not even a continuous histogram). Also: "There are 3 ways to change the X and Y axis limits. ....Warning: Items 2 and 3 will delete the datapoints that lie outisde the limit from the data itself. So, if you add any smoothing line line and such, the outcome will be distorted" So, is this a graphics module, or a fitting module, or a data manipulation…

You're right, its not really a reference. But with the understanding, one should be quipped with the knowledge to make any ggplot. It's meant to be a tutorial that explains the structure to make any ggplot. Especially for beginners for whom the ggplot syntax didn't immediately click and those who struggle for long trying to get their ggplot right.
Post reply on HN