Plot All Columns of Data Frame in R (3 Examples) | Base R vs. ggplot2 | How to Draw Each Variable

preview_player
Показать описание
R code of this video:

y1 = rnorm(10),
y2 = runif(10),
y3 = rpois(10, 1))

plot(data$x, data$y1, type = "l", col = 1, ylim = c(- 3, 3)) # Plot with Base R
lines(data$x, data$y2, type = "l", col = 2)
lines(data$x, data$y3, type = "l", col = 3)

y = c(data$y1, data$y2, data$y3),
group = c(rep("y1", nrow(data)),
rep("y2", nrow(data)),
rep("y3", nrow(data))))

library("ggplot2")

ggp <- ggplot(data_ggp, aes(x, y, col = group)) + # Create ggplot2 plot
geom_line()
ggp # Draw plot

ggp + facet_grid(group ~ .) # Draw plot in different panels

Follow me on Social Media:
Рекомендации по теме
Комментарии
Автор

I was figuring out it for 2 hours and you explained it in 6 minutes.
Thx dude!

FreeDay
Автор

many thanks for what you are doing
your videos and website are of great help

StefanoVerugi
Автор

when reshaping the data frame, it returns me an error: Error:
! Tibble columns must have compatible sizes.
• Size 97: Existing data.
• Size 485: Column `y`.
ℹ Only values of size one are recycled., how can I resolve this?

cathrynguo
Автор

Help, please! line graph does not appear for my data. This appeared on my console "geom_line()`: Each group consists of only one observation.
ℹ Do you need to adjust the group aesthetic?"

ashjanmoh
Автор

Thanks for the nice video! I have problems to use it with different series lengths. It is possible to draw different time series (with different length) in seperated plots in one window with ggplot? :)

piamuller
welcome to shbcf.ru