How to change the legend breaks

How can I put in the subtitle the small point to? Starting before 5?

library(tidyverse, quietly = TRUE)
binary_data <- data.frame(stringsAsFactors=FALSE,
                          Especies = c( "Epinephelus fuscoguttatus",
                                        "Epinephelus guttatus",
                                        "Epinephelus itajara",
                                        "Epinephelus marginatus",
                                        "Epinephelus polyphekadion",
                                        "Epinephelus rivulatus",
                                        "Mycteroperca bonaci",
                                        "Mycteroperca olfax",
                                        "Plectropomus leopardus",
                                        "Plectropomus maculatus",
                                        "Plectropomus punctatus",
                                        "Alphestes afer",
                                        "Dermatolepis dermatolepis",
                                        "Epinephelus fuscoguttatus",
                                        "Epinephelus guttatus",
                                        "Epinephelus itajara",
                                        "Epinephelus marginatus",
                                        "Epinephelus ongus",
                                        "Epinephelus polyphekadion",
                                        "Epinephelus striatus",
                                        "Mycteroperca bonaci",
                                        "Mycteroperca jordani",
                                        "Mycteroperca prionura",
                                        "Mycteroperca rosacea",
                                        "Mycteroperca tigris",
                                        "Mycteroperca venenosa",
                                        "Mycteroperca xenarcha",
                                        "Paralabrax clathratus",
                                        "Paralabrax nebulifer",
                                        "Plectropomus areolatus"
                          ),
                          Hemisfério = c("HS",
                                         "HS",
                                         "HS",
                                         "HS",
                                         "HS",
                                         "HS",
                                         "HS",
                                         "HS",
                                         "HS",
                                         "HS",
                                         "HS",
                                         "HN",
                                         "HN",
                                         "HN",
                                         "HN",
                                         "HN",
                                         "HN",
                                         "HN",
                                         "HN",
                                         "HN",
                                         "HN",
                                         "HN",
                                         "HN",
                                         "HN",
                                         "HN",
                                         "HN",
                                         "HN",
                                         "HN",
                                         "HN",
                                         "HN"
                          ),
                          primavera = c(1,
                                        0,
                                        1,
                                        1,
                                        1,
                                        0,
                                        1,
                                        1,
                                        1,
                                        1,
                                        0,
                                        0,
                                        0,
                                        1,
                                        0,
                                        0,
                                        0,
                                        1,
                                        1,
                                        1,
                                        1,
                                        1,
                                        1,
                                        1,
                                        1,
                                        1,
                                        0,
                                        1,
                                        0,
                                        1
                          ),
                          ver√£o = c(1,
                                    1,
                                    1,
                                    1,
                                    1,
                                    0,
                                    0,
                                    1,
                                    1,
                                    1,
                                    1,
                                    0,
                                    0,
                                    1,
                                    1,
                                    1,
                                    1,
                                    0,
                                    1,
                                    1,
                                    1,
                                    1,
                                    0,
                                    1,
                                    0,
                                    0,
                                    1,
                                    1,
                                    1,
                                    0
                          ),
                          outono = c(1,
                                     0,
                                     1,
                                     0,
                                     1,
                                     0,
                                     0,
                                     0,
                                     0,
                                     0,
                                     0,
                                     0,
                                     0,
                                     1,
                                     0,
                                     0,
                                     0,
                                     0,
                                     0,
                                     0,
                                     1,
                                     1,
                                     0,
                                     1,
                                     0,
                                     0,
                                     1,
                                     1,
                                     0,
                                     0
                          ),
                          inverno = c(0,
                                      0,
                                      0,
                                      0,
                                      1,
                                      1,
                                      1,
                                      0,
                                      0,
                                      0,
                                      0,
                                      1,
                                      1,
                                      1,
                                      1,
                                      0,
                                      0,
                                      0,
                                      1,
                                      1,
                                      1,
                                      0,
                                      0,
                                      0,
                                      1,
                                      1,
                                      0,
                                      0,
                                      0,
                                      1
                          )
)
>binary_data %>%
  gather(Estação, Presence, primavera:inverno) %>% 
  group_by(Hemisfério, Estação) %>% 
  summarise(species_count = sum(Presence)) %>%
  ggplot(aes(x = Estação, y = Hemisfério)) +
  geom_point(aes(size = species_count, color = species_count)) +
  scale_size_continuous(range = c(3,18)) +
  guides(colour = guide_legend()) + 
  labs(color = 'N√ļmero de esp√©cies',
       size = 'N√ļmero de esp√©cies') +
  theme_classic() + scale_colour_gradient(low="#000066",high="#000066")

image
to be like this subtitle (starting in 1 to 10 or include the small circles too)
image

Do you mean a subtitle for your plot (i.e. the subtitle argument that you pass to labs())?

Nice little post on ggplot2 titles, subtitles, and captions here:

not exactly the subtitle, more like the scale of the subtitle. i would like to have more intervals instead of just 5, 7.5 and 10.

thanks

Just to clarify you are referring to the legend of the plot not the subtitle

1 Like

You can set the size, range, and breaks using scale_size().

You can change the breaks like this, and btw if you don't want the color to change with the count, you can just take the color argument out of the aes() statement.

binary_data %>%
    gather(Estação, Presence, primavera:inverno) %>% 
    group_by(Hemisfério, Estação) %>% 
    summarise(species_count = sum(Presence)) %>%
    ggplot(aes(x = Estação, y = Hemisfério)) +
    geom_point(aes(size = species_count), color = "#000066") +
    scale_size_continuous(range = c(3,18), breaks = c(3, 6, 9, 12)) +
    labs(size = 'N√ļmero de esp√©cies') +
    theme_classic()

2 Likes

just one more thing, can you help me to put the season in the order outono, inverno, primavera and ver√£o?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.