Draw Plot with Circle in R (3 Examples) | Base R & plotrix Package vs. ggplot2 & ggforce Packages
Автор: Statistics Globe
Загружено: 2022-06-25
Просмотров: 1342
How to draw circles in the R programming language. More details: https://statisticsglobe.com/draw-plot...
R code of this video:
set.seed(394567) # Create example data
data <- data.frame(x = rnorm(100),
y = rnorm(100))
head(data) # Print example data
plot(data$x, data$y) # Draw Base R plot without circle
install.packages("plotrix") # Install plotrix package
library("plotrix") # Load plotrix package
plot(data$x, data$y) # Draw Base R plot with circle
draw.circle(0, 0, 1)
install.packages("ggplot2") # Install & load ggplot2 package
library("ggplot2")
ggplot(data, aes(x, y)) + # Draw ggplot2 plot without circle
geom_point()
install.packages("ggforce") # Install ggforce package
library("ggforce") # Load ggforce package
data_circle <- data.frame(x0 = 0, # Create data for circle
y0 = 0,
r = 1)
data_circle # Print data for circle
ggplot() + # Draw ggplot2 plot with circle
geom_point(data = data, aes(x, y)) +
geom_circle(data = data_circle, aes(x0 = x0, y0 = y0, r = r))
data_circle2 <- data.frame(x0 = 1:5, # Create data for multiple circles
y0 = 1:5,
r = 1:5)
data_circle2 # Print data for multiple circles
ggplot() + # Draw ggplot2 plot with multiple circles
geom_point(data = data, aes(x, y)) +
geom_circle(data = data_circle2, aes(x0 = x0, y0 = y0, r = r, col = r))
Follow me on Social Media:
Facebook – Statistics Globe Page: / statisticsglobecom
Facebook – Group for Discussions & Questions: / statisticsglobe
LinkedIn – Statistics Globe Page: / statisticsglobe
LinkedIn – Group for Discussions & Questions: / 12555223
Twitter: / joachimschork
Music by bensound.com
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: