Skip to content

geom_baseball doesn't connect well with other data sets #6

Open
@billyfryer

Description

@billyfryer

Hey Ross, here is some sample code of the issue I am running into. It isn't a big deal with the way this data is set up, but when I have many geom_point() functions, it starts to become a little tedious. Ideally, I'd like to do the plot on top rather than the top on bottom. The difference being that I can have a ggplot statement that takes care of the data rather than putting data = in the geom_point(). The error I get says "Error in ggplot_add():! Can't add sportyR::geom_baseball(league = "MLB") to a ggplot object. Run rlang::last_error() to see where the error occurred."

# Sample data
x <- c(96.49, 108.33, 98.68, 65.81, 111.83,
       109.20, 105.26, 70.63, 129.80, 63.18)
y <- c(161.63, 148.44, 158.33, 177.18, 160.22,
       160.69, 163.51, 156.92, 154.09, 170.11)

data <- data.frame(x,y)

# What I'd like to do, but doesn't work
ggplot(data = data) +
  geom_point(aes(x = x,
                            y = y),
             stroke = 1,
             size = 5,
color = "blue") +
  labs(title = "Sample Data",
       color = "Result") +
theme(plot.title = element_text(hjust = 0.5)) +
  sportyR::geom_baseball(league = "MLB")


# What I have to do instead
sportyR::geom_baseball(league = "MLB") +
  geom_point(data = data,
         aes(x = x,
             y = y),
         color = "blue",
         stroke = 1,
         size = 5) +
  labs(title = "Sample Data",
       color = "Result") +
theme(plot.title = element_text(hjust = 0.5))

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions