0

I am trying to build a dumbbell plot (geom_dumbbell) in ggplot. The plot builds fine, but when I try and add details around the point color and size the plot fails to inherit aes, spewing:

Error: mapping must be created by aes()

Here is the code to generate a reproducible example:

test <- data.frame(Scenario = rep(c("LC-HD", "HC-HD", "LC-LD", "HC-LD"), times = 2),  
           technology = c("P", "W", "P", "W", "P", "W", "P", "W"),
           country = paste("country", rep(seq(1, 4, by = 1), times = 2)), 
           low = runif(8, min = 1, max = 3), 
           high = runif(8, min = 4, max = 6))

The following code runs fine:

library(ggplot2)
library(ggalt)
ggplot(test, aes(x = low, xend = high, y = country, group = country)) + 
  geom_dumbbell(color="grey", 
                size = 1) + 
  facet_grid(technology ~ Scenario) +
  coord_flip() + 
  theme(axis.text.x = element_text(angle = 90)) 

However when I make the below changes to the geom_dumbbell layer (setting point colours and sizes):

library(devtools)
library(ggplot2)
library(ggalt)
ggplot(test, aes(x = low, xend = high, y = country, group = country)) + 
  geom_dumbbell(color="grey", 
                size = 1, 
                point.size.l = 1.5, point.size.r = 1,5, 
                point.colour.l = "#58d9ef", point.colour.r = "#a3c4dc") +
  facet_grid(technology ~ Scenario) +
  coord_flip() + 
  theme(axis.text.x = element_text(angle = 90))

I get the error:

Error: mapping must be created by aes()

Even if i try set inherit.aes = T, explicitly in the geom_bumbbell layer, i still get the error.

The problem seems to be with the point.size argument as adding this gives the error. When i just add point.colour arguments, i get:

Warning: Ignoring unknown parameters: point.color.l, point.color.r

This is strange as these are parameters described in the documentation: https://www.rdocumentation.org/packages/SciencesPo/versions/1.4.1/topics/geom_dumbbell

I am running ggalt_0.6.1 (which loads geom_dumbbell)

What am i missing here. Why does adding details on the points change the way aes is inherited, and why aren't point.colour parameters recognized?

MorrisseyJ
  • 1,191
  • 12
  • 19
  • 2
    One thing you may want to confirm in your question is the version of `geom_dumbell` you are using. – steveb Aug 27 '18 at 15:57
  • 3
    When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Since we don't have the data in `results` we can't run and test the code to see what's going on. – MrFlick Aug 27 '18 at 16:02
  • In your example code you have a comma instead of a period for `point.size.r = 1,5`. Changing that might help – see24 Aug 27 '18 at 17:34
  • MrFlick, i added code to generate reproducible example. steveb, i added info about running version 0.6.1 of ggalt that loads geom_dumbbell (i think this is what your question was asking, and i think its the latest version). see24, when change the comma to a point (good catch) i get: Warning: Ignoring unknown parameters: point.size.l, point.size.r, point.color.l, point.color.r. Why are these parameters not identified if i am running an up to date version of ggalt (i think)? – MorrisseyJ Aug 27 '18 at 20:37

1 Answers1

1

Worked this out.

Error: mapping must be created by aes()

Was caused by the comma in point.size.r.

Warning: Ignoring unknown parameters: point.color.l, point.color.r

Was caused by using the wrong names.

Those should be:

point.size.l = size_x
point.size.r = size_xend
point.color.l = colour_x
point.color.r = colour_xend

Solution was here: Ignoring unknown parameters: point.colour.1

Apologies for the confusing question title. I am not sure how one edits the documentation: https://www.rdocumentation.org/packages/SciencesPo/versions/1.4.1/topics/geom_dumbbell

MorrisseyJ
  • 1,191
  • 12
  • 19