Skip to content

Extra (unwanted) geoms in the legend #572

Description

@yankev
The code:
library(plotly)

dat1 <- data.frame(
  sex = factor(c("Female","Female","Male","Male")),
  time = factor(c("Lunch","Dinner","Lunch","Dinner"), levels=c("Lunch","Dinner")),
  total_bill = c(13.53, 16.81, 16.24, 17.42)
)

ggplot(data=dat1, aes(x=time, y=total_bill, group=sex, shape=sex, colour=sex)) +
  geom_line(aes(linetype=sex), size=1) +     # Set linetype by sex
  geom_point(size=5) +         # Use larger points, fill with white
  scale_colour_hue(name="Sex",      # Set legend title
                   l=30)  +                  # Use darker colors (lightness=30)
  scale_shape_manual(name="Sex",
                     values=c(22,21)) +      # Use points with a fill color
  scale_linetype_discrete(name="Sex") +
  xlab("Time of day") + ylab("Total bill") + # Set axis labels
  ggtitle("Average bill for 2 people") +     # Set title
  theme_bw()

ggplotly()
The ggplot version:

image

The ggplotly version:

screen shot 2016-05-04 at 5 46 01 pm

Session Info:

sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.9.4 (Mavericks)

locale:
[1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] plotly_3.4.13 ggplot2_2.1.0

loaded via a namespace (and not attached):
[1] Rcpp_0.12.4 tidyr_0.4.1 assertthat_0.1 dplyr_0.4.3
[5] digest_0.6.9 grid_3.2.3 plyr_1.8.3 R6_2.1.2
[9] DBI_0.3.1 jsonlite_0.9.19 gtable_0.2.0 magrittr_1.5
[13] scales_0.4.0 httr_1.1.0 viridis_0.3.4 labeling_0.3
[17] tools_3.2.3 htmlwidgets_0.6 munsell_0.4.3 yaml_2.1.13
[21] parallel_3.2.3 base64enc_0.1-3 colorspace_1.2-6 htmltools_0.3.5
[25] gridExtra_2.2.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions