Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for implementation of aes(shape = ..) in tidyplot() function #45

Open
ar-puuk opened this issue Jan 12, 2025 · 2 comments
Open

Comments

@ar-puuk
Copy link

ar-puuk commented Jan 12, 2025

Description

Currently, I am only able to pick a shape in add_data_points(), however, it is sometimes useful to vary the point shapes by a variable. I tried passing in the shape argument in tidyplot assuming it would pass on to ggplot2::aes() (as I inferred from the function description).

Reprex

Provide the data and code to reproduce the bug. (I am sorry, reprex is having issues uploading images to imgur for some reason)

# install.packages("ggplot2")
# install.packages("tidyplots")
# install.packages("palmerpenguins")

library(ggplot2)
library(tidyplots)
library(palmerpenguins)

# Reference Plot in ggplot2 ----

ggplot2::ggplot(
  data = palmerpenguins::penguins,
  mapping = aes(
    x = bill_depth_mm,
    y = bill_length_mm
  )
) +
  geom_point(
    aes(
      color = species,
      shape = species
    ),
    size = 3,
    alpha = 0.8
  ) +
  geom_smooth(method = lm, se = FALSE, aes(color = species))

# Closest I could get using tidyplots ----

palmerpenguins::penguins |>
  tidyplot(
    x = bill_depth_mm,
    y = bill_length_mm,
    color = species,
    # shape = species, # shape argument could go here or within the add_data_points() function
    width = 133,
    height = 100
  ) |>
  add_data_points(size = 3, alpha = 0.8) |>
  add_curve_fit(linewidth = 0.75, method = "lm", alpha = 0)

Versions

Share your versions of tidyplots and ggplot2.
To check your versions, run sessionInfo() in the R console.

other attached packages:
[1] shiny_1.10.0         palmerpenguins_0.1.1 tidyplots_0.2.0      ggplot2_3.5.1 
@jbengler
Copy link
Owner

Hi @ar-puuk

you are right! Currently, tidyplots only supports x, y, and color as the three main aesthetics. By the way, in tidyplots there is only one aesthetic for color that is propagated to both color and fill.

This was an active decision to take out complexity. However, I understand that ggplot2 users might feel constrained or limited. I will for sure not implement all ggplot2 aesthetics. But I see the value especially in shape, size.

I have to think this through a little bit more, but an idea would be to implement this a a new add_data_shapes(), while leaving add_data_points() untouched.

Best
Jan

@ar-puuk
Copy link
Author

ar-puuk commented Jan 14, 2025

I agree. shape and size are the aesthetics I frequently use with geom_point(). It would also be cool to implement linewidth and linetype for geom_lines() or other line geometries. However, there is a chance I might be becoming greedy here since at this point maybe just using add(ggplot2::geom_point(aes(shape = x))) would be easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants