1

What I'm trying to do is overlay circles that have a dark outline over the ones I have but I'm not sure how to size them since I already have varying sizes. Also is there anyway to change the legend symbols to something like $1M, $2m?

Graph

mikebay_usergraph <- 
  ggplot(mikebay_movies_dt, aes(y = tomatoUserMeter, x = Released, label = Title)) +
  geom_point(aes(size = BoxOffice)) + (aes(color = tomatoImage)) + 
  geom_text(hjust = .45, vjust = -.75, family = "Futura", size = 5, colour = "#535353") +
  ggtitle("The Fall of Bayhem: How Michael Bay movies have declined") +
    theme(plot.title = element_text(size = 15, vjust = 1, family = "Futura"),
          axis.text.x  = element_text(size = 12.5, family = "Futura"),
          axis.text.y  = element_text(size = 12.0, family = "Futura"),
          panel.background = element_rect(fill = '#F0F0F0'),
          panel.grid.major=element_line(colour ="#D0D0D0",size=.75)) +
  scale_colour_manual(values = c('#336333', '#B03530')) +
  geom_hline(yintercept = 0,size = 1.2, colour = "#535353") +
  scale_x_date(limits = c(as.Date("1994-1-1"),as.Date("2017-1-1"))) +  
  theme(axis.ticks = element_blank())
Phillip Black
  • 105
  • 1
  • 2
  • 10
  • 1
    Please add the data to make a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – tonytonov Jul 08 '15 at 19:33

1 Answers1

1

I offer two possible solutions for adding a circle or outline around size-scaled points in a scatterplot. For the first solution, I propose using plotting symbols that allow separate fill and outline colors. The drawback here is that you cannot control the thickness of the outline. For the second solution I propose adding an extra layer of slightly larger black points positioned under the primary geom_point layer. In this case, the thickness of the outline can be manually adjusted by setting thickness to a value between 0 and 1.

Finally, dollar legend formatting can be added by loading the scales package, and adding scale_size_continuous(labels=dollar) to your ggplot call.

library(ggplot2)
library(scales) # Needed for dollar labelling.

dat = data.frame(rating=c(80, 60, 40),
                 date=as.Date(c("1995-1-1", "2005-1-1", "2015-1-1")),
                 boxoffice=c(3e7, 1e8, 7e7),
                 tomato=c("fresh", "rotten", "rotten"))

p1 = ggplot(dat, aes(x=date, y=rating, size=boxoffice, fill=tomato)) +
     geom_point(shape=21, colour="black") +
     scale_fill_manual(values = c(fresh="green", rotten="red")) +
     scale_size_continuous(labels=dollar, range=c(8, 22))

thickness = 0.35

p2 = ggplot(dat, aes(x=date, y=rating)) +
     geom_point(colour="black", 
                aes(size=boxoffice + (thickness * mean(boxoffice)))) +
     geom_point(aes(colour=tomato, size=boxoffice)) +
     scale_colour_manual(values = c(fresh="green", rotten="red")) +
     scale_size_continuous(labels=dollar, range=c(8, 22), name="Box Office")

enter image description here

bdemarest
  • 14,397
  • 3
  • 53
  • 56
  • I tried doing this before. The key, and thanks for point this out, is that my geom_points were not ordered right. Can I ask how you got such smooth circles? – Phillip Black Jul 08 '15 at 21:09
  • 1
    Smoothness is because antialiasing is active by default on mac os. Supposedly you can get similar results on windows or linux by installing the Cairo graphics device libraries, and specifying `png(..., type="cairo", antialias="gray")`. I tried to test it out on a Win7 virtual machine but I couldn't get any form of antialiasing to work. – bdemarest Jul 08 '15 at 22:49
  • This is completely random, but would you mind running a chunk of code in R Markdown? I'm trying to prepare a work portfolio and I just can't seem to get it to work. [link] https://docs.google.com/document/d/1OPu5AGgmQocYAkbqintZhCajoDyt2-gt7yXeJVwbnDU/edit – Phillip Black Jul 10 '15 at 15:04
  • I gave it a try, but I can't get past this error: `rottenrate(mikebay_movies$Film[2]) Error in file(con, "r") : cannot open the connection`. – bdemarest Jul 10 '15 at 19:03
  • God me neither. I opened a separate question about it. – Phillip Black Jul 10 '15 at 19:31