Skip to content

Commit

Permalink
correct area in bubble plot; fixes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed Jun 16, 2015
1 parent 4a352ca commit a4e98f6
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 36 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
^\.Rproj\.user$
^data-raw$
^README\.Rmd$
^README\.html$
^README_files/*
^cran-comments\.md$
19 changes: 11 additions & 8 deletions R/country_colors.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,23 @@
#' scale_colour_manual(values = country_colors) +
#' guides(color = guide_legend(reverse = TRUE))
#'
#' # spaghetti plot for lots of countries
#' ggplot(subset(gapminder, continent != "Oceania"),
#' aes(x = year, y = lifeExp, group = country, color = country)) +
#' geom_line(lwd = 1, show_guide = FALSE) + facet_wrap(~ continent) +
#' scale_color_manual(values = country_colors) +
#' theme_bw() + theme(strip.text = element_text(size = rel(1.1)))
#'
#' ggplot(subset(gapminder, year == 2007 & continent != "Oceania"),
#' aes(x = gdpPercap, y = lifeExp)) +
#' scale_x_log10(limits = c(150, 115000)) + ylim(c(16, 96)) +
#' geom_point(aes(size = sqrt(pop/pi)), pch = 21, color = 'grey20',
#' show_guide = FALSE) + scale_size_continuous(range=c(1,40)) +
#' facet_wrap(~ continent) + coord_fixed(ratio = 1/43) +
#' aes(fill = country) + scale_fill_manual(values = country_colors) +
#' theme_bw() + theme(strip.text = element_text(size = rel(1.1)))
#' # bubble plot for lots of countries
#' gap_bit <- subset(gapminder, year == 2007 & continent != "Oceania")
#' gap_bit <- gap_bit[with(gap_bit, order(continent, -1 * pop)), ]
#' ggplot(gap_bit, aes(x = gdpPercap, y = lifeExp, size = pop)) +
#' scale_x_log10(limits = c(150, 115000)) + ylim(c(16, 96)) +
#' geom_point(pch = 21, color = 'grey20', show_guide = FALSE) +
#' scale_size_area(max_size = 40) +
#' facet_wrap(~ continent) + coord_fixed(ratio = 1/43) +
#' aes(fill = country) + scale_fill_manual(values = country_colors) +
#' theme_bw() + theme(strip.text = element_text(size = rel(1.1)))
#' }
#'
"country_colors"
22 changes: 11 additions & 11 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ gapminder
=========

```{r setup, include = FALSE, cache = FALSE}
knitr::opts_chunk$set(collapse = TRUE)
knitr::opts_chunk$set(collapse = TRUE, dpi = 300)
```

Excerpt from the [Gapminder](http://www.gapminder.org/data/) data. This R data package provides the data as a data.frame and in plain text delimited form. Package includes premade color schemes for the countries and continents.
Expand Down Expand Up @@ -110,18 +110,18 @@ ggplot(subset(gapminder, continent != "Oceania"),
geom_line(lwd = 1, show_guide = FALSE) + facet_wrap(~ continent) +
scale_color_manual(values = country_colors) +
theme_bw() + theme(strip.text = element_text(size = rel(1.1)))
ggplot(subset(gapminder, year == 2007 & continent != "Oceania"),
aes(x = gdpPercap, y = lifeExp)) +
scale_x_log10(limits = c(150, 115000)) + ylim(c(16, 96)) +
geom_point(aes(size = sqrt(pop/pi)), pch = 21, color = 'grey20',
show_guide = FALSE) + scale_size_continuous(range=c(1,40)) +
facet_wrap(~ continent) + coord_fixed(ratio = 1/43) +
aes(fill = country) + scale_fill_manual(values = country_colors) +
theme_bw() + theme(strip.text = element_text(size = rel(1.1)))
```
gap_bit <- subset(gapminder, year == 2007 & continent != "Oceania")
gap_bit <- gap_bit[with(gap_bit, order(continent, -1 * pop)), ]
ggplot(gap_bit, aes(x = gdpPercap, y = lifeExp, size = pop)) +
scale_x_log10(limits = c(150, 115000)) + ylim(c(16, 96)) +
geom_point(pch = 21, color = 'grey20', show_guide = FALSE) +
scale_size_area(max_size = 40) +
facet_wrap(~ continent) + coord_fixed(ratio = 1/43) +
aes(fill = country) + scale_fill_manual(values = country_colors) +
theme_bw() + theme(strip.text = element_text(size = rel(1.1)))
```

### Description of the dataset

Expand Down
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,17 @@ ggplot(subset(gapminder, continent != "Oceania"),
![](README_files/figure-markdown_github/demo-country-colors-ggplot2-2.png)

``` r

ggplot(subset(gapminder, year == 2007 & continent != "Oceania"),
aes(x = gdpPercap, y = lifeExp)) +
scale_x_log10(limits = c(150, 115000)) + ylim(c(16, 96)) +
geom_point(aes(size = sqrt(pop/pi)), pch = 21, color = 'grey20',
show_guide = FALSE) + scale_size_continuous(range=c(1,40)) +
facet_wrap(~ continent) + coord_fixed(ratio = 1/43) +
aes(fill = country) + scale_fill_manual(values = country_colors) +
theme_bw() + theme(strip.text = element_text(size = rel(1.1)))

gap_bit <- subset(gapminder, year == 2007 & continent != "Oceania")
gap_bit <- gap_bit[with(gap_bit, order(continent, -1 * pop)), ]

ggplot(gap_bit, aes(x = gdpPercap, y = lifeExp, size = pop)) +
scale_x_log10(limits = c(150, 115000)) + ylim(c(16, 96)) +
geom_point(pch = 21, color = 'grey20', show_guide = FALSE) +
scale_size_area(max_size = 40) +
facet_wrap(~ continent) + coord_fixed(ratio = 1/43) +
aes(fill = country) + scale_fill_manual(values = country_colors) +
theme_bw() + theme(strip.text = element_text(size = rel(1.1)))
```

![](README_files/figure-markdown_github/demo-country-colors-ggplot2-3.png)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-markdown_github/test-drive-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 11 additions & 8 deletions man/country_colors.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,23 @@ ggplot(h_dat, aes(x = year, y = lifeExp)) +
scale_colour_manual(values = country_colors) +
guides(color = guide_legend(reverse = TRUE))

# spaghetti plot for lots of countries
ggplot(subset(gapminder, continent != "Oceania"),
aes(x = year, y = lifeExp, group = country, color = country)) +
geom_line(lwd = 1, show_guide = FALSE) + facet_wrap(~ continent) +
scale_color_manual(values = country_colors) +
theme_bw() + theme(strip.text = element_text(size = rel(1.1)))

ggplot(subset(gapminder, year == 2007 & continent != "Oceania"),
aes(x = gdpPercap, y = lifeExp)) +
scale_x_log10(limits = c(150, 115000)) + ylim(c(16, 96)) +
geom_point(aes(size = sqrt(pop/pi)), pch = 21, color = 'grey20',
show_guide = FALSE) + scale_size_continuous(range=c(1,40)) +
facet_wrap(~ continent) + coord_fixed(ratio = 1/43) +
aes(fill = country) + scale_fill_manual(values = country_colors) +
theme_bw() + theme(strip.text = element_text(size = rel(1.1)))
# bubble plot for lots of countries
gap_bit <- subset(gapminder, year == 2007 & continent != "Oceania")
gap_bit <- gap_bit[with(gap_bit, order(continent, -1 * pop)), ]
ggplot(gap_bit, aes(x = gdpPercap, y = lifeExp, size = pop)) +
scale_x_log10(limits = c(150, 115000)) + ylim(c(16, 96)) +
geom_point(pch = 21, color = 'grey20', show_guide = FALSE) +
scale_size_area(max_size = 40) +
facet_wrap(~ continent) + coord_fixed(ratio = 1/43) +
aes(fill = country) + scale_fill_manual(values = country_colors) +
theme_bw() + theme(strip.text = element_text(size = rel(1.1)))
}
}
\seealso{
Expand Down

0 comments on commit a4e98f6

Please sign in to comment.