Skip to content

Discrete example in stat_summary doesn't work after 3.3.2 #4150

Closed

Description

@margoal1

The example "Orientation follows the discrete axis" in stat_summary (lines 55 to 58) doesn't demonstrate what it claims to after the ggplot2 update to v3.3.2 (it did work in 3.3.0). The example doesn't actually follow the discrete axis. In order for it to demonstrate what it claims to, cyl should be replaced with factor(cyl) or a similar discrete datatype. See details below.

# install / load ggplot2 v 3.3.0
# run below example

# Orientation follows the discrete axis
ggplot(mtcars, aes(mpg, cyl)) +
 geom_point() +
 stat_summary(fun.data = "mean_cl_boot", colour = "red", size = 2)

You will get a plot that summarizes mpg by groups of cyl, this is the presumed desired behavior based on the title of the example
image

# install / load ggplot2 v 3.3.2
# run below example

# Orientation follows the discrete axis
ggplot(mtcars, aes(mpg, cyl)) +
 geom_point() +
 stat_summary(fun.data = "mean_cl_boot", colour = "red", size = 2)

Now you will get a plot that summarizes cyl by mpg,
but this doesn't match the behavior implied by the title for the example "Orientation follows the discrete axis"
image

In order for this example to work with v 3.3.2, the y-mapped variable has to result in a mapped_discrete datatype
For example, you could update the example as follows (replacing cyl with factor(cyl)):

# Orientation follows the discrete axis
ggplot(mtcars, aes(mpg, factor(cyl))) +
 geom_point() +
 stat_summary(fun.data = "mean_cl_boot", colour = "red", size = 2) 

image

Activity

  1. yutannihilation commented on Jul 29, 2020

    @yutannihilation
    Member

    cyl should be replaced with factor(cyl)

    Thanks, agreed. Would you like to contribute a pull request?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions