Jon K
Jon K

Reputation: 51

Legends overlay one another in ggplot2

I am trying to create a bubbleplot with a regression line in ggplot2. When I add the regression line, it overlays my bubbleplot symbols (dollar signs) in the legend with solid blocks of blue color. I have tried using the guide=FALSE option but it does nothing. Any suggestions?

Here is my code:

ggplot(data, aes(x=Protein, y=Yield, size=Revenue))+
  geom_point(color="darkgreen", pch=36)+
  geom_smooth(method=lm, se=FALSE, guide=FALSE)+
  scale_size_continuous(range = c(5, 15), name="Revenue \n ($/acre)")

enter image description here

Sample data:

data <- structure(list(Variety = structure(c(3L, 27L, 6L, 11L, 19L, 37L, 
8L, 25L, 9L, 31L, 28L, 5L, 22L, 24L, 26L, 20L, 2L, 15L, 32L, 
34L, 17L, 10L, 4L, 12L, 7L, 1L, 35L, 36L, 14L, 30L, 21L, 18L, 
23L, 29L, 33L, 16L, 13L, 38L), .Label = c("ADVANCE", "BARLOW", 
"BOLLES", "BREAKER", "BRICK", "BRIGGS", "ELGIN", "FALLER", "FOCUS", 
"FOREFRONT", "GLENN", "HRS3361", "HRS3378", "HRS3419", "LCS-BREAKAWAY", 
"LCS-IGUACU", "LCS-POWERPLAY", "LCS ALBANY", "LINKERT", "MOTT", 
"MS-CHEVELLE", "MS-STINGRAY", "NORDEN", "PREVAIL", "PROSPER", 
"RB07", "ROLLAG", "SABIN", "SAMSON", "SELECT", "SY-INGMAR", "SY-ROWYN", 
"TRAVERSE", "VELVA", "WB-DIGGER", "WB-MAYVILLE", "WB9507", "WB9879CLP"
), class = "factor"), Yield = c(67L, 65L, 63L, 62L, 63L, 71L, 
75L, 75L, 69L, 69L, 68L, 66L, 78L, 70L, 66L, 66L, 64L, 64L, 69L, 
59L, 67L, 65L, 67L, 67L, 65L, 67L, 64L, 62L, 72L, 64L, 68L, 72L, 
63L, 60L, 73L, 70L, 64L, 54L), Protein = c(15.4, 15.2, 15, 15.3, 
15.2, 14.7, 14.1, 14.1, 14.7, 14.7, 14.6, 14.9, 13.2, 14.3, 14.7, 
14.8, 14.8, 14.9, 14.3, 14.7, 14.5, 14.8, 14.4, 14.6, 14.7, 14.4, 
14.6, 14.9, 13.7, 14.7, 13.9, 13.4, 14.3, 14.7, 14.2, 13.5, 14.2, 
14.6), Revenue = c(488.26, 463.03, 443.34, 442.94, 437.6, 422.38, 
412.77, 410.67, 409.94, 409.71, 404.03, 402.4, 401.16, 395.3, 
394.27, 390.75, 390.31, 388.31, 387.65, 387.65, 387.37, 387.33, 
386.94, 386.78, 385.22, 380.88, 377.94, 377.15, 372.56, 368.17, 
366.36, 361.5, 356.49, 354.51, 353.18, 351.53, 350.13, 314.2)), 
.Names = c("Variety", "Yield", "Protein", "Revenue"), 
class = "data.frame", row.names = c(NA,-38L))

Upvotes: 0

Views: 192

Answers (1)

Rorschach
Rorschach

Reputation: 32426

You just need show_guide = FALSE.

ggplot(data, aes(x=Protein, y=Yield, size=Revenue))+
  geom_point(color="darkgreen", pch=36)+
  geom_smooth(method=lm, se=FALSE, show_guide=FALSE)+
  scale_size_continuous(range = c(5, 15), name="Revenue \n ($/acre)")

Upvotes: 1

Related Questions