Visible aesthetics IN TR OD U C TION TO DATA VISU AL IZATION W ITH G G P L OT 2 Rick Sca v e � a Fo u nder , Sca v e � a Academ y
Mapping onto the X and Y a x es ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point() INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
Mapping onto color ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point() T y pe Variable Color Species INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
Mapping onto the color aesthetic ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point() T y pe Variable Color Species Species , a dataframe col u mn , is mapped onto color , a v isible aesthetic . INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
Mapping onto the color aesthetic ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point() T y pe Variable Color Species Species , a dataframe col u mn , is mapped onto color , a v isible aesthetic . Map aesthetics in aes() . INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
Mapping onto the color aesthetic in geom ggplot(iris) + geom_point(aes(x = Sepal.Length, y = Sepal.Width, col = Species)) Onl y necessar y if : All la y ers sho u ld not inherit the same aesthetics Mi x ing di � erent data so u rces INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
T y pical v isible aesthetics Aesthetic Description x X a x is position y Y a x is position INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
T y pical v isible aesthetics Aesthetic Description x X a x is position y Y a x is position � ll Fill color INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
T y pical v isible aesthetics Aesthetic Description x X a x is position y Y a x is position � ll Fill color color Color of points , o u tlines of other geoms INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
T y pical v isible aesthetics Aesthetic Description x X a x is position y Y a x is position � ll Fill color color Color of points , o u tlines of other geoms si z e Area or radi u s of points , thickness of lines INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
T y pical v isible aesthetics Aesthetic Description Aesthetic Description x X a x is position alpha Transparenc y y Y a x is position � ll Fill color Color of points , o u tlines of other color geoms Area or radi u s of points , si z e thickness of lines INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
T y pical v isible aesthetics Aesthetic Description Aesthetic Description x X a x is position alpha Transparenc y y Y a x is position linet y pe Line dash pa � ern � ll Fill color Color of points , o u tlines of other color geoms Area or radi u s of points , si z e thickness of lines INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
T y pical v isible aesthetics Aesthetic Description Aesthetic Description x X a x is position alpha Transparenc y y Y a x is position linet y pe Line dash pa � ern � ll Fill color labels Te x t on a plot or a x es Color of points , o u tlines of other color geoms Area or radi u s of points , si z e thickness of lines INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
T y pical v isible aesthetics Aesthetic Description Aesthetic Description x X a x is position alpha Transparenc y y Y a x is position linet y pe line dash pa � ern � ll Fill color labels Te x t on a plot or a x es Color of points , o u tlines of other shape Shape color geoms Area or radi u s of points , si z e thickness of lines INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
Let ' s Practice IN TR OD U C TION TO DATA VISU AL IZATION W ITH G G P L OT 2
Using attrib u tes IN TR OD U C TION TO DATA VISU AL IZATION W ITH G G P L OT 2 Rick Sca v e � a Fo u nder , Sca v e � a Academ y
Aesthetics ? Attrib u tes ! ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point(color = "red") T y pe Propert y Color " red " Set a � rib u tes in geom_*() . The color a � rib u te is set to " red " . INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
Aesthetics ? Attrib u tes ! ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point(size = 10) T y pe Propert y Si z e 4 INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
Aesthetics ? Attrib u tes ! ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point(shape = 4) T y pe Propert y Shape 4 INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
Let ' s practice ! IN TR OD U C TION TO DATA VISU AL IZATION W ITH G G P L OT 2
Modif y ing Aesthetics IN TR OD U C TION TO DATA VISU AL IZATION W ITH G G P L OT 2 Rick Sca v e � a Fo u nder , Sca v e � a Academ y
Positions Adj u stment for o v erlapping identit y dodge stack � ll ji � er ji � erdodge n u dge INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
position = " identit y" ( defa u lt ) ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point() INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
position = " identit y" ( defa u lt ) ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point(position = "identity") INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
position = " jitter " ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point(position = "jitter") INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
position _ jitter () posn_j <- position_jitter(0.1) ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, col = Species)) + geom_point(position = posn_j) INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
position _ jitter () posn_j <- position_jitter(0.1, seed = 136) ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point(position = posn_j) Set arg u ments for the position Consistenc y across plots & la y ers INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
Scale f u nctions scale_x_*() scale_y_*() scale_color_*() Also scale_colour_*() scale_fill_*() scale_shape_*() scale_linetype_*() scale_size_*() INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
Scale f u nctions scale_x_continuous() scale_y_*() scale_color_discrete() Alternati v el y, scale_colour_*() scale_fill_*() scale_shape_*() scale_linetype_*() scale_size_*() INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
scale _*_*() ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point(position = "jitter") + scale_x_continuous("Sepal Length") + scale_color_discrete("Species") INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
The limits arg u ment ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point(position = "jitter") + scale_x_continuous("Sepal Length", limits = c(2,8)) + scale_color_discrete("Species") INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
The breaks arg u ment ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point(position = "jitter") + scale_x_continuous("Sepal Length", limits = c(2, 8), breaks = seq(2, 8, 3)) + scale_color_discrete("Species") INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
The e x pand arg u ment ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point(position = "jitter") + scale_x_continuous("Sepal Length", limits = c(2, 8), breaks = seq(2, 8, 3), expand = c(0, 0)) + scale_color_discrete("Species") INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
The labels arg u ment ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point(position = "jitter") + scale_x_continuous("Sepal Length", limits = c(2, 8), breaks = seq(2, 8, 3), expand = c(0, 0), labels = c("Setosa", "Versicolor", "Virginica")) + scale_color_discrete("Species") INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
labs () ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point(position = "jitter") + labs(x = "Sepal Length", y = "Sepal Width", color = "Species") INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
Let ' s tr y it o u t ! IN TR OD U C TION TO DATA VISU AL IZATION W ITH G G P L OT 2
Aesthetics best practices IN TR OD U C TION TO DATA VISU AL IZATION W ITH G G P L OT 2 Rick Sca v e � a Fo u nder , Sca v e � a Academ y
Which aesthetics ? Use y o u r creati v e kno w- ho w, and Follo w some clear g u idelines Jacq u es Bertin The Semiolog y of Graphics , 1967 William Cle v eland The Elements of Graphing Data , 1985 Vis u ali z ing Data , 1993 INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
Form follo w s f u nction INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
Form follo w s f u nction F u nction G u iding principles Primar y: Ne v er : Acc u rate and e � cient representations Misrepresent or obsc u re data Secondar y: Conf u se v ie w ers w ith comple x it y Al w a y s : Vis u all y appealing , bea u tif u l plots Consider the a u dience and p u rpose of e v er y plot INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
INTRODUCTION TO DATA VISUALIZATION WITH GGPLOT 2
Recommend
More recommend