R-Studio Tutorial: Multiple Lines in One Plot With GGPlot

preview_player
Показать описание
In today's video, we are going to discover how to create a plot in ggplot2 for R that contains multiple lines in the same graphic. We are also going to add dots to the lines to make each datapoint more visible.

If you liked this #tutorial, make sure to subscribe to the channel for updates on future videos with similar content.

Also, you might want to check out the #GGPlot playlist here:

If you have any questions about this video or GGPlot in general, leave them down below in the comments and I'll do my best to answer them.
Рекомендации по теме
Комментарии
Автор

This is one of the few videos I have found showing how to combine ggplot and wide format data. Thank you.

ProfBoggs
Автор

Thanks a lot! I was breaking my head for the past 3 hours because I was getting so many errors. This saved my day and grades for my assignment.

reshjnithin
Автор

Just started rstudio last week and was having difficulties with two line plot, this is tremendous! Would love to see you apply loess\lowess smoothing to this chart. Thank you for your easy and straightforward tutorials 👍

keiserious
Автор

At a loss for words. It save me from a lot of headache. Much appreciated.

zahrasadatvaziri
Автор

As someone just starting out with learning to use RStudio, this video has been by far the most helpful for me so far. What a hero, thanks so much for the explanation!

fransingolf
Автор

Awesome video! Been searching forever to find this specific information. Thank you!!

michaelpappas
Автор

You've literally saved my butt in my statistics course at university, thank you! (:

Lara-zogn
Автор

Great explanation; a real time-saver! Thank you!

gregmoore
Автор

Thank you sir, you have saved my keister.

viantube_
Автор

Thank you! I have been struggling for awhile to get a nice plot out and this video helped alot

andrewjohnson
Автор

I could do my homework, thanks to your video :)

lizbethmujica
Автор

11:04 It is not a good solution for ylab (what about if you have to add another line..). I will recommend :
ylab = "Effectif" (or something else ) and adding a *legend* with "blue" armed forces etc...

WahranRai
Автор

Very helpful. I kindly request for a video on how to add a legend, given 2 y variables. Thanks

midasmageto
Автор

This was a really useful video. Thanks for this.
I wondered if you had any advice on how to connect two points with a line using the mean of different columns in a dataset?
I have tried using different methods but I thought the following would work in R but it doesn't.
ggplot()+
geom_point(data = wsd, mapping = aes(x = "Mud intact", y = mean(Mud_intact)), colour = "blue", size = 3)+
geom_point(data = wsd, mapping = aes(x = "Sand intact", y = mean(Sand_intact)), colour = "blue", size = 3)+
geom_line()+
geom_point(data = wsd, mapping = aes(x = "Mud hair cut", y = mean(Mud_hair.cut)), colour = "red", size = 3)+
geom_point(data = wsd, mapping = aes(x = "Sand hair cut", y = mean(Sand_hair.cut)), colour = "red", size = 3)+
geom_line()+
labs(title = "Comparison of mean worm speed with/without hairs on different substrates", x = "Worm condition and Surface type", y = "Mean Speed")+
theme_bw()

Any advice greatly appreciated.

jcornish
Автор

I have a 300 x 450 matrix, 300 samples with 450 factors. I´d like to plot the 300 lines in a graph (if possible, 5 diferent colors to represent categories which samples belong to), i´ve tried many approaches, now I have transposed the data, and can´t find a way to put column data [2:454] versus x=column 1. in other words, is there a way to plot 200 collumns without having to write one by one?

ChristianoSts
Автор

Hello, and how would it be if instead of 2 graphs I wanted to make 3 or more on the same graph? Could you help me please? Thank you very much.

alvarodel
Автор

I have a small R script below that creates a graph.
This script only imports one .csv to .tsv file.
However, I need to tweak it in a way that it can import multiple .tsv files and create overlaying graphs (transparent histogram and line) with different colours.
Can you do it for me?
# read in data
df = read.csv("your_distribution.tsv", sep="\t")

# filter Ks distribution (0.001 < Ks < 5)
lower_bound = 0.001
upper_bound = 5
df = df[df$Ks < upper_bound, ]
df = df[df$Ks > lower_bound, ]

# perform node-averaging (redo when applying other filters)
dff = aggregate(df$Ks, list(df$Family, df$Node), mean)

# reflect the data around the lower Ks bound to account for boundary effects
ks = c(dff$x, -dff$x + lower_bound)

# plot a histogram and KDE on top
hist(ks, prob=TRUE, xlim=c(0, upper_bound), n=50)
lines(density(ks), xlim=c(0, upper_bound))

ardykharabian
Автор

If it is vertex in linear graph, the area of highest value in ggplot is called as?

athiribacha
Автор

muhcas gracias amigo me ayudo mucho manita arriba

JouikisShow
Автор

thanks god someone posted it ! and could you specify how to add independent legend on the sides of the plot? instead of renaming the y-axis. Thanks !!

travisjiang