seancarmody / ngramr

R package to query the Google Ngram Viewer
Other
48 stars 9 forks source link

fix labels #9

Closed briatte closed 11 years ago

briatte commented 11 years ago

The discrete scale needs labels to be manually set to preserve upper case in the keywords. Here's an example:

ggram(c("USSR", "Russia"),
      year_start = 1900,
      corpus = "eng_gb_2012", 
      geom = "area",
      geom_options = list(position = "stack"),
      ignore.case = TRUE) + 
  aes_string(fill = "Phrase") + 
  scale_x_continuous(breaks = 1900 + 10*0:11) +
  scale_fill_discrete("", labels = c("USSR", "Russia"))

seancarmody commented 11 years ago

Really appreciate your contributions here!

seancarmody commented 11 years ago
ggram(c("USSR", "Russia"),
  year_start = 1900,
  corpus = "eng_gb_2012", 
  geom = "area",
  geom_options = list(position = "stack"),
  ignore.case = TRUE)

This behaves OK now, albeit with lower case labels.

briatte commented 11 years ago

Just add labels = phrases to the scale_colour_continuous and scale_fill_continuous parameters at lines 54-55 of ggram, and the uppercase will be back :)

seancarmody commented 11 years ago

Thanks...adapted this a bit so it works with aggregate=FALSE.

seancarmody commented 11 years ago

Note: I have changed from ignore.case to ignore_case.

briatte commented 11 years ago

May I ask why that last change? ignore.case shares similarity with the same argument in grepl, so I would favour that name.

seancarmody commented 11 years ago

Good question! I used to use . a lot (a lot of older R functions use it to, grepl being an example). More recently I have switched to Hadley Wickham's style and use _ instead. I don't think there is a single best answer and it is a controversial subject.

briatte commented 11 years ago

Okay. I was curious to know if there was any technical reason. I like the convention anarchy in R, so it's fine with me, but perhaps you could avoid users making mistakes by simply adding ignore.case = ignore_case, which would then allow both argument names?

briatte commented 11 years ago

P.S. I'd like to add arguments to pass Ngram syntax to ngram. Are you fine with this?

These would allow, for instance, to automatically consider all keywords as adjectives, as in blue_ADJ red_ADJ.

I'll draft some code and submit it now if it works for you.

seancarmody commented 11 years ago

Good idea.

seancarmody commented 11 years ago

Latest push allows either ignore_case or ignore.case.