File: ggplot2.R

package info (click to toggle)
r-cran-units 0.8-1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,068 kB
  • sloc: xml: 2,437; cpp: 175; sh: 13; makefile: 2
file content (23 lines) | stat: -rw-r--r-- 781 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
library(ggplot2)
library(units)
mtcars$consumption <- set_units(mtcars$mpg, mi / gallon)
mtcars$power <- set_units(mtcars$hp, hp)
ggplot(mtcars) + geom_point(aes(power, consumption))
ggplot(mtcars) + geom_point(aes(1/power, 1/consumption))

# to generate figure 1 in vignette:

#pdf("fig1.pdf", width = 4, height = 4)
library(units)
units_options(negative_power = TRUE)
mtcars$consumption <- set_units(mtcars$mpg, mi / gallon)
mtcars$displacement <- set_units(mtcars$disp, "in^3")
units(mtcars$displacement) <- "cm^3"
units(mtcars$consumption) <- "km/l"
m = par("mar")
m[3] = 0.1
par(mar = m + c(0, .3, 0, 0))
with(mtcars, plot(1/displacement, 1/consumption))
#pdf("fig2.pdf", width = 4, height = 4)
library(ggplot2)
ggplot(mtcars) + geom_point(aes(1/displacement, 1/consumption))