Scatterplot Matrix in R markdown

Is there a way to produce high-quality scatterplot matric in R markdown. I would like to be able to understand the density of the plot more. Perhaps something like resizing.

It seems okay outside of the R markdown.


pairs(airpollution)

Hi @user124578,

Personally, I recommend using ggplot2 for your graphing purposes. Another package named ggforce has provided a extra ggplot2 functionality that does precisely what you are looking for (and a whole lot more). Try this out and let me know what you think:

library(ggplot2)
library(ggforce)

airquality %>% 
  ggplot() +
  geom_point(aes(x = .panel_x, y = .panel_y)) +
  facet_matrix(vars(everything()))

Basically you can replace everything() with the specific variables you want to plot if you do not want all of them plotted at once.

Thanks for this. I am still having the issue where the plot isn't very clear when i am knitting as PDF. It doesn't really show the specfic details for each facet. It's very hard to compare as reader. if i run the code in the R console it fine and I am able to get insights of the data. I think it something to do with r markdown on how it render the file.

Ah I understand, try playing with some of the chunk options for figure resolution, like this:

```{r dpi=500}
airquality %>% 
  ggplot() +
  geom_point(aes(x = .panel_x, y = .panel_y)) +
  facet_matrix(vars(everything()))
```

Unfortunately, this didn't work. I think i might go down the root of adding as an image to the R Markdown file.

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue so we can take a look for ourselves? Please have a look at this guide, to see how to create one:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.