| 1 |
library(ggplot2) |
| 2 |
library(units) |
| 3 |
mtcars$consumption <- set_units(mtcars$mpg, mi / gallon) |
| 4 |
mtcars$power <- set_units(mtcars$hp, hp) |
| 5 |
ggplot(mtcars) + geom_point(aes(power, consumption)) |
| 6 |
ggplot(mtcars) + geom_point(aes(1/power, 1/consumption)) |
| 7 |
|
| 8 |
# to generate figure 1 in vignette: |
| 9 |
|
| 10 |
#pdf("fig1.pdf", width = 4, height = 4) |
| 11 |
library(units) |
| 12 |
units_options(negative_power = TRUE) |
| 13 |
mtcars$consumption <- set_units(mtcars$mpg, mi / gallon) |
| 14 |
mtcars$displacement <- set_units(mtcars$disp, "in^3") |
| 15 |
units(mtcars$displacement) <- "cm^3" |
| 16 |
units(mtcars$consumption) <- "km/l" |
| 17 |
m = par("mar") |
| 18 |
m[3] = 0.1 |
| 19 |
par(mar = m + c(0, .3, 0, 0)) |
| 20 |
with(mtcars, plot(1/displacement, 1/consumption)) |
| 21 |
#pdf("fig2.pdf", width = 4, height = 4) |
| 22 |
library(ggplot2) |
| 23 |
ggplot(mtcars) + geom_point(aes(1/displacement, 1/consumption)) |