neuhausi / canvasXpress

CanvasXpress: A JavaScript Library for Data Analytics with Full Audit Trail Capabilities.
http://www.canvasXpress.org
289 stars 44 forks source link

Could canvasXpress respect `theme(legend.justification = c(0, 1)` in ggplot2? #149

Closed davidhodge931 closed 4 months ago

davidhodge931 commented 5 months ago

I want to be able to put the legend top-right, top-left or bottom-left as the alignment looks good

library(tidyverse)
library(palmerpenguins)
library(canvasXpress)

p <- penguins |> 
  ggplot() +
  geom_point(aes(x = flipper_length_mm, 
                 y = body_mass_g, 
                 colour = species)) +
  theme(legend.justification = c(0,1))

p

canvasXpress(p)

image

neuhausi commented 5 months ago

Fixed in 48.6 cX-htmlwidget-f3a2c6d06713768fd836-cx

davidhodge931 commented 5 months ago

Works awesome when legend is on right.

Could this work when the legend is on the top or bottom?

neuhausi commented 5 months ago

Yes. That will require a little bit of work since R flattens the legend when is top or bottom. Example?

neuhausi commented 5 months ago

I used an example in your website

penguins |>
  gg_histogram(
    x = flipper_length_mm,
    col = species,
    title = "Penguin flipper length by species",
    subtitle = "Palmer Archipelago, Antarctica",
    caption = "Source: Gorman, 2020", 
    mode = light_mode_t(),
  ) +
  labs(colour = NULL, fill = NULL)

When I inspect the ggplot object the theme for the legend justification is legend.justification" = c("0", "0.5") This is the plot I get with CanvasXpress. Perhaps I don't understand the way the justification is set. Does this mean align the legend to 50% of the width? Could you help my understanding. I see your plot that the legend is all the way to the left.

cX-htmlwidget-5f0d625c494b7e33cfe2-cx

neuhausi commented 5 months ago

I just released version 48.7. Please check and close issues as needed

davidhodge931 commented 5 months ago

legend.justification element 1 refers to the hjust between 0 (left) and 1 (right).

legend.justification element 2 refers to the vjust between 0 (bottom) and 1 (top).

I use c(0, 1) for my *_mode_r theme with the legend on right, and c(0, 0.5) for the *_mode_t and *_mode_b one.

Cool, you are using ggblanket! Now you can see where my questions are coming from :)

davidhodge931 commented 5 months ago

Also, there is theme(legend.location = "plot") or theme(legend.location = "panel") to consider to.

This says whether to consider the legend justification with regard to the plot or panel.

I use panel for my *_mode_r themes and plot for my *_mode_t and *_mode_b themes

neuhausi commented 5 months ago

Ok So there are pretty much binary for the x coordinate yes or no?

Here are another two plots I am fixing in the next release ;-)

cX-htmlwidget-db2114ff29b7d3ae7020-cx

cX-htmlwidget-fc621f62a3fc381792d5-cx

They don't work in the current version :-(

neuhausi commented 5 months ago

legend.justification element 1 refers to the hjust between 0 (left) and 1 (right).

legend.justification element 2 refers to the vjust between 0 (bottom) and 1 (top).

I use c(0, 1) for my *_mode_r theme with the legend on right, and c(0, 0.5) for the *_mode_t and *_mode_b one.

Cool, you are using ggblanket! Now you can see where my questions are coming from :)

I want you to use CanvasXpress :-)

davidhodge931 commented 5 months ago

They are any decimal between 0 and 1 (e.g. 0.86)

neuhausi commented 4 months ago

Fixed in version 48.9. Can you provide an example with vertical justification when the legend is right or left. Thank you.

cX-htmlwidget-fc621f62a3fc381792d5-cx

davidhodge931 commented 4 months ago
penguins |>
  gg_histogram(
    x = flipper_length_mm,
    col = species,
    title = "Penguin flipper length by species",
    subtitle = "Palmer Archipelago, Antarctica",
    caption = "Source: Gorman, 2020", 
  ) 
neuhausi commented 4 months ago

Thank you cX-htmlwidget-e2f1325e7e3e66900d70-cx

davidhodge931 commented 4 months ago

Looks pretty good. Perhaps the alignment looks slightly too low?

image

davidhodge931 commented 4 months ago

histogram is dropping the legend title

image

neuhausi commented 4 months ago

Fixed in Version 49.1