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

SpectrumLegend wrong alpha values #3

Closed
danpal96 opened this issue Sep 27, 2023 · 1 comment · Fixed by #4
Closed

SpectrumLegend wrong alpha values #3

danpal96 opened this issue Sep 27, 2023 · 1 comment · Fixed by #4

Comments

@danpal96
Copy link

r-base 4.2.3
r-plottools 0.2.0
r-ggplot2 3.4.3
Tested using jupyterlab

I think that SpectrumLegend is displaying the wrong alpha values.

This is the code that I used to compare with ggplot2:

plot.new()

palette <- viridisLite::viridis(256L, alpha = 0.5)

# Continuous legend for colour scale
PlotTools::SpectrumLegend(
  "topleft",
  legend = round(seq(1.0, 0.0, length.out = 4), 3),
  palette = palette,
  bty = "n",    # No framing box
  inset = 0.02,
  xpd = NA      # Do not clip at edge of figure
)

library(ggplot2)

ggplot(mtcars, aes(mpg, cyl, color=disp)) +
    geom_point() +
    scale_color_gradientn(colors=palette)

Comparisons with ggplot2:

With alpha=0.5
SpectrumLegend
image
ggplot2
image
With alpha=0.1
SpectrumLegend
image
ggplot2
image

@ms609
Copy link
Owner

ms609 commented Sep 27, 2023

Hi, thanks for noticing this, and for the clear report!

The issue is arising as the individual line segments that together comprise the legend line are overlapping. As an immediate workaround you can add the parameter lend = "butt" to the function call. I'll update the code to make this the default setting anon.

@ms609 ms609 linked a pull request Sep 27, 2023 that will close this issue
@ms609 ms609 closed this as completed in #4 Sep 28, 2023
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

Successfully merging a pull request may close this issue.

2 participants