2023-03-31
mpg |> ggplot(aes(x = displ, y = hwy, size = class)) + geom_point()
mpg |> ggplot(aes(x = displ, y = hwy)) + geom_point(size = 1)
mpg |> ggplot(aes(x = displ, y = hwy, alpha = class)) + geom_point()
mpg |> ggplot(aes(x = displ, y = hwy)) + geom_point(alpha = 0.25)
mpg |> ggplot(aes(x = displ, y = hwy, shape = class)) + geom_point()
plot(0:25, 0:25, pch = 0:25)
mpg |> ggplot(aes(x = displ, y = hwy)) + geom_point(shape = 5)
mpg |> ggplot(aes(x = displ, y = hwy, color = class)) + geom_point()
mpg |> ggplot(aes(x = displ, y = hwy)) + geom_point(color = “blue”)
mpg |> ggplot(aes(x = displ, y = hwy, color = “blue”)) + geom_point()
color
argument applies to points, lines, text, and borderseither mapped to data mpg |> ggplot(aes(x = class, color = class)) + geom_bar(show.legend = FALSE)
or uniformly mpg |> ggplot(aes(x = class)) + geom_bar(color = “blue”)
fill
arugment applies to filled areaseither mapped to data mpg |> ggplot(aes(x = class, fill = class)) + geom_bar(show.legend = FALSE)
or uniformly mpg |> ggplot(aes(x = class)) + geom_bar(fill = “blue”)
mpg |> ggplot(aes(x = displ, y = hwy, group = drv)) + geom_smooth()
mpg |> ggplot(aes(x = displ, y = hwy, linetype = drv)) + geom_smooth()
mpg |> ggplot(aes(x = displ, y = hwy, color = drv)) + geom_smooth(show.legend = FALSE)
mpg |> ggplot(aes(x = displ, y = hwy)) + geom_point() + geom_smooth(aes(linetype = drv))
mpg |> ggplot(aes(x = displ, y = hwy)) + geom_point(aes(color = class)) + geom_smooth()
mpg |> ggplot(aes(x = displ, y = hwy, color = drv)) + geom_point() + geom_smooth(aes(linetype = drv))
mpg |> ggplot(aes(x = displ, y = hwy)) + geom_point() + geom_smooth(aes(color = drv, fill = drv), alpha = 0.5)
ggplot can calculate statistics on the fly, and many geoms have some underlying statistical transformation diamonds
diamonds |> ggplot(aes(x = cut)) + geom_bar()
diamonds |> ggplot(aes(x = cut, y = depth)) + geom_point()
diamonds |> ggplot(aes(x = cut, y = depth)) + stat_summary()
diamonds |> ggplot(aes(x = cut, y = depth)) + stat_summary(fun.min = min, fun.max = max, fun = median)
diamonds |> ggplot(aes(x = cut, y = depth)) + stat_summary(fun.data = mean_cl_normal)
Coloring by group can be difficult to visualize with many groups mpg |> ggplot(aes(x = displ, y = hwy, color = class)) + geom_point()
mpg |> ggplot(aes(x = displ, y = hwy)) + geom_point() + facet_wrap(~ class)