![]() ![]() # 4 - add aes() with the correct mapping to geom_smooth()ĭia_plot + geom_smooth(aes(col =clarity), se =FALSE) # `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")' # 3 - add geom_smooth() with se set to FALSEĭia_plot + geom_smooth(se = FALSE) # `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")' # 2 - add geom_point() with alpha set to 0.2ĭia_plot <- dia_plot + geom_point(alpha=0.2) Understanding the grammar: explore mixing arguments and aesthetics in a single geometry** # 1 - Create dia_plot objectĭia_plot <- ggplot(diamonds, aes(x = carat, y = price)) # Add the same geom layer, but with aes() inside ![]() # Add a geom layer with + and geom_point() Understanding the grammar: adding layeats to to build beautiful & informative plots # Create the object containing the data and aes layers: dia_plotĭia_plot <- ggplot(diamonds, aes(x = carat, y = price))+ Plot only the points with argument alpha. # 4 - Keep the color settings from previous command. Ggplot(diamonds, aes(x = carat, y = price, color=clarity)) + Ggplot(diamonds, aes(x = carat, y = price)) + Geom_smooth() # `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'Įxploring ggplot2, part 5: more possibilities of combining geoms, using alpha # 2 - show only the smooth line ![]() # Add geom_point() and geom_smooth() with + Ggplot(diamonds, aes(x = carat, y = price))+ Str(diamonds) # Classes 'tbl_df', 'tbl' and 'ame': 53940 obs. # Explore the diamonds data frame with str() For the next exercises, you’ll be using a subset of 1,000 diamonds. Among the variables included are carat (a measurement of the size of the diamond) and price. Ggplot(mtcars, aes(x = wt, y = mpg, size = disp)) +Įxploring ggplot2: using geom:point() and geom_smooth() The diamonds data frame contains information on the prices and various metrics of 50,000 diamonds. Ggplot(mtcars, aes(x = wt, y = mpg, color = disp)) + ![]() #Grammar of Graphics **aestetics: using color and size # A scatter plot Ggplot(mtcars, aes(x = factor(cyl), y = mpg)) + mtcars$am <-factor(mtcars$am)Ĭyl (the number of cylinders) is categorical, it is classified as numeric in mtcars. Library(ggplot2) # Warning: package 'ggplot2' was built under R version 3.4.4 # Explore the mtcars data frame with str() Basic ggplot2 commands.build a plot of the mtcars dataset that contains information about 32 cars from a 1973 Motor Trend magazine. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |