jtlandis / ggside

ggplot2 extension allowing for plotting various geometries as side panels using the ggplot2 API
Other
337 stars 16 forks source link

ggside PKG is superb + a quick Q #60

Open sfd99 opened 1 month ago

sfd99 commented 1 month ago

Hi Justin,

ggside PKG is superb!

Is it possible to add more than 1 ggside plot along both the x and y axes?.

ie: both, a ggside Boxplot and a ggside Histogram plots on the x AND also on the Y side of a plot?. Can you give a concrete, simple R code example?

Thanks!! sfd99 San Francisco.

jtlandis commented 1 month ago

Hi @sfd99, I'm glad you find ggside helpful. Just to make sure I understand your question, are you asking if you can add a geom_xsideboxplot() and geom_xsidehistogram() and then also do the same with geom_ysideboxplot() and geom_ysidehistogram()?

library(ggside)
#> Loading required package: ggplot2
#> Registered S3 method overwritten by 'ggside':
#>   method from   
#>   +.gg   ggplot2

# the easy case is adding separate geometries to either side.
ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Species)) +
  geom_point() +
  geom_xsidehistogram(aes(fill = Species)) +
  geom_ysideboxplot(orientation = "x")
#> `stat_xsidebin()` using `bins = 30`. Pick better value with `binwidth`.


# ggside at this moment does not support adding multiple `geom_xside*` geometries
# to the same side but in separate panels. You can however use a less advertised function
# position_rescale(). This function is rather defunct and was added very early in `ggside`'s 
# lifecycle. In-fact, I omitted `position_xrescale()` from the below example because it appears
# to be bugged.
# the intention behind `position_rescale()` is to control where items are rendered in a single
# panel. I haven't yet attempted to make geometries in separate panels because that would
# complicate `ggside`'s compatibility with `facet_grid()`/`facet_wrap()`:
ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Species)) +
  geom_point() +
  geom_xsidehistogram(aes(fill = Species)) +
  geom_xsideboxplot(orientation = "y", 
                    aes(y = as.integer(Species)),
                    position = position_yrescale(range = 25,
                                                 midpoint = 60)) +
  geom_ysidehistogram(aes(fill = Species))
#> `stat_xsidebin()` using `bins = 30`. Pick better value with `binwidth`.
#> `stat_ysidebin()` using `bins = 30`. Pick better value with `binwidth`.

Created on 2024-09-04 with reprex v2.1.1

sfd99 commented 1 month ago

Hi Justin,

thks for the quick reply!

Yes, that's what I meant:

" ...adding multiple geom_xside* geometries to the same side but in separate panels ... ".

Understood, it's NA (reliably) presently in the pkg .

But... do keep the feature in mind for future versions of the great ggside PKG!. :-)

Thanks! sfd99 San Francisco.