ggplot2
can seem too complicated.diamonds
, mpg
and economics
which come built in with the ggplot2
package.diamonds
, mpg
and economics
which come built in with the ggplot2
package.diamonds
, mpg
and economics
which come built in with the ggplot2
package.diamonds
data contains data on the price, size and quality of over 50000 diamonds.ggplot
maps aesthetics to geometries ggplot(data = diamonds,mapping = aes(x=price))
geom_histogram
function.ggplot(data = diamonds,mapping = aes(x=price))+ geom_histogram()
geom_histogram
function.ggplot(data = diamonds,mapping = aes(x=price))+ geom_histogram(bins = 5)
ggplot(data = diamonds,mapping = aes(x=price))+ geom_histogram(bins = 5, boundary=0)
ggplot(data = diamonds,mapping = aes(x=price))+ geom_histogram(binwidth = 500)
ggplot(data = diamonds,mapping = aes(x=price))+ geom_histogram(binwidth = 500,fill = 'red')
ggplot(data = diamonds,mapping = aes(x=price))+ geom_histogram(binwidth = 500,color='white', fill = 'blue')
fill
or color
argument of geom_histogram
.ggplot(data = diamonds,mapping = aes(x=price))+ geom_histogram(binwidth = 500,color='white', fill = '#b35900')
ggplot(data = diamonds,mapping = aes(x=price))+ geom_histogram(fill='#00471b',color='#eee1c6')
geom_density
.geom_density
.geom_density
.geom_density
.ggplot2
.ggplot(data = diamonds,mapping = aes(x=price))+ geom_density()
ggplot(data = diamonds,mapping = aes(x=price))+ geom_density(size=3)
ˆf(x)=1nn∑i=1Kh(x−xi)
geom_density
geom_density
ggplot(data = diamonds,mapping = aes(x=price))+ geom_density(bw=100)
ggplot(data = diamonds,mapping = aes(x=price))+ geom_density(bw=2000)
ggplot(data = diamonds,mapping = aes(x=price))+ geom_density(bw=0.0001)
ggplot(data = diamonds,mapping = aes(x=price))+ geom_density(bw=80000)
ggplot(data = diamonds,mapping = aes(x=carat))+ geom_histogram()
ggplot(data = diamonds,mapping = aes(x=carat))+ geom_rug()
ggplot(data = diamonds,mapping = aes(y=carat))+ geom_boxplot()
coef
argument to geom_boxplot
. coef
argument to geom_boxplot
. ggplot(data = diamonds,mapping = aes(y=carat))+ geom_boxplot(coef=4)
ggplot(data = mpg,mapping = aes(y=cty))+ geom_boxplot(notch = T)
str
functionstr(diamonds)
## tibble [53,940 × 10] (S3: tbl_df/tbl/data.frame)## $ carat : num [1:53940] 0.23 0.21 0.23 0.29 0.31 0.24 0.24 0.26 0.22 0.23 ...## $ cut : Ord.factor w/ 5 levels "Fair"<"Good"<..: 5 4 2 4 2 3 3 3 1 3 ...## $ color : Ord.factor w/ 7 levels "D"<"E"<"F"<"G"<..: 2 2 2 6 7 7 6 5 2 5 ...## $ clarity: Ord.factor w/ 8 levels "I1"<"SI2"<"SI1"<..: 2 3 5 4 2 6 7 3 4 5 ...## $ depth : num [1:53940] 61.5 59.8 56.9 62.4 63.3 62.8 62.3 61.9 65.1 59.4 ...## $ table : num [1:53940] 55 61 65 58 58 57 57 55 61 61 ...## $ price : int [1:53940] 326 326 327 334 335 336 336 337 337 338 ...## $ x : num [1:53940] 3.95 3.89 4.05 4.2 4.34 3.94 3.95 4.07 3.87 4 ...## $ y : num [1:53940] 3.98 3.84 4.07 4.23 4.35 3.96 3.98 4.11 3.78 4.05 ...## $ z : num [1:53940] 2.43 2.31 2.31 2.63 2.75 2.48 2.47 2.53 2.49 2.39 ...
str(mpg)
## tibble [234 × 11] (S3: tbl_df/tbl/data.frame)## $ manufacturer: chr [1:234] "audi" "audi" "audi" "audi" ...## $ model : chr [1:234] "a4" "a4" "a4" "a4" ...## $ displ : num [1:234] 1.8 1.8 2 2 2.8 2.8 3.1 1.8 1.8 2 ...## $ year : int [1:234] 1999 1999 2008 2008 1999 1999 2008 1999 1999 2008 ...## $ cyl : int [1:234] 4 4 4 4 6 6 6 4 4 4 ...## $ trans : chr [1:234] "auto(l5)" "manual(m5)" "manual(m6)" "auto(av)" ...## $ drv : chr [1:234] "f" "f" "f" "f" ...## $ cty : int [1:234] 18 21 20 21 16 18 18 18 16 20 ...## $ hwy : int [1:234] 29 29 31 30 26 26 27 26 25 28 ...## $ fl : chr [1:234] "p" "p" "p" "p" ...## $ class : chr [1:234] "compact" "compact" "compact" "compact" ...
geom_bar
ggplot(data = diamonds, mapping = aes(x=cut))+ geom_bar()
ggplot(data = mpg, mapping = aes(x=manufacturer))+ geom_bar()
x
aestheticy
aestheticgeom_point
.diamonds
datasetggplot(data = diamonds, mapping = aes(x=carat,y=price))+geom_point()
ggplot(data = diamonds, mapping = aes(x=carat,y=price))+ geom_point(size=0.1)
ggplot(data = diamonds, mapping = aes(x=carat,y=price))+ geom_point(alpha=0.2)
ggplot(data = diamonds, mapping = aes(x=carat,y=price))+ geom_bin2d()
ggplot(data = diamonds, mapping = aes(x=carat,y=price))+ geom_hex()
ggplot(data = diamonds, mapping = aes(x=carat,y=price))+ geom_density2d()
str(economics)
## tibble [574 × 6] (S3: spec_tbl_df/tbl_df/tbl/data.frame)## $ date : Date[1:574], format: "1967-07-01" "1967-08-01" ...## $ pce : num [1:574] 507 510 516 512 517 ...## $ pop : num [1:574] 198712 198911 199113 199311 199498 ...## $ psavert : num [1:574] 12.6 12.6 11.9 12.9 12.8 11.8 11.7 12.3 11.7 12.3 ...## $ uempmed : num [1:574] 4.5 4.7 4.6 4.9 4.7 4.8 5.1 4.5 4.1 4.6 ...## $ unemploy: num [1:574] 2944 2945 2958 3143 3066 ...
ggplot(economics, aes(x=date, y=unemploy))+ geom_line()
ggplot(data = diamonds, mapping = aes(x=carat,y=price))+ geom_point()
ggplot(data = diamonds, mapping = aes(x=carat,y=price))+ geom_point()+scale_x_log10()+scale_y_log10()
Prob(r)=r−sK
Pr(r)≈r−s/K
log(f(r))≈−slog(r)−log(K)
ggplot(data = diamonds, mapping = aes(x=cut,y=price))+ geom_boxplot()
ggplot(data = diamonds, mapping = aes(x=price,y=cut))+ geom_boxplot()
ggplot(data = mpg, mapping = aes(x=drv,y=hwy))+ geom_boxplot(notch=T)
ggplot(data = diamonds, mapping = aes(x=cut,y=price))+ geom_violin()
ggplot(data = diamonds, mapping = aes(x=cut,y=price))+ geom_violin()+coord_flip()
ggplot(data = mpg, mapping = aes(x=cyl,y=cty))+ geom_point(position = 'jitter')
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |