R programming | Start building graphs with ggplot2 in R
Автор: rdatacode
Загружено: 2023-09-15
Просмотров: 358
R programming Section 5. Using R graphic ggplot2. Lecture 1. Start building graphs with ggplot2.
The first function in building a graph is the ggplot() function. It specifies the following: The data frame containing the data to be plotted.
Geoms are the geometric objects (points, lines, bars, and shaded regions) that can be placed on a ggplot() graph, They are added using functions whose names begin with geom_. Functions are chained together with ggplot() using the + sign to build a final plot:
some common and frequently used geoms:
geom_bar() bar chart
geom_boxplot() Box plot
geom_density() Density plot
geom_histogram() Histogram
Add a scatter plot of Years and Salary using geom_point() and + sign, functions are chained together using the + sign to build a final plot:
ggplot(data = Income, mapping = aes(x = Years, y = Salary)) +
geom_point(color = "cornflowerblue", alpha = .7, size = 1.5) +
theme_bw()
Add another geom in the graph: a fitted line with linear regression to summarize the trend
ggplot(data = Income,
mapping = aes(x = Years, y = Salary)) +
geom_point(color = "cornflowerblue", alpha = .7, size = 1.5) +
theme_bw() +
geom_smooth(method = "lm")
#rprogramming
#rstudio
#ggplot
#ggplot2
#graph
#geom
#rdatacode
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: