- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to plot rows of a data frame as lines in R?
To plot row of a data frame as lines, we can use matplot function but we would need to transpose the data frame because transposed values of the data frame will be read as columns and the matplot function plot the columns not rows. For example, if we have a data frame called df then the plot of rows as lines can be created by using the command −
Consider the below data frame −
> x1<-rpois(5,2) > x2<-rpois(5,5) > x3<-rpois(5,3) > df1<-data.frame(x1,x2,x3) > df1
x1 x2 x3 1 0 9 5 2 3 4 2 3 0 2 1 4 3 7 3 5 5 10 3
Creating plot of rows in df1 as lines −
> y1<-rnorm(3) > y2<-rnorm(3) > y3<-rnorm(3) > df2<-data.frame(y1,y2,y3) > df2
y1 y2 y3 1 -0.9992381 -1.3802480 -0.7228096 2 1.3677936 0.1813761 1.3711921 3 0.8905198 -1.0607813 0.3895616 1 -0.9992381 -1.3802480 -0.7228096 2 1.3677936 0.1813761 1.3711921 3 0.8905198 -1.0607813 0.3895616
Creating plot of rows in df2 as lines −
- How to plot matrix columns as lines in base R?
- How to extract a single column of an R data frame as a data frame?
- How to create barplot from data frame in R using rows as categories?
- How to select rows of a data frame that are not in other data frame in R?
- How to delete rows in an R data frame?
- How to add rows in an R data frame?
- How to create a vector of data frame values by rows in R?
- How to convert columns of an R data frame into rows?
- How to plot all the values of an R data frame?
- How to extract unique combination of rows in an R data frame?
- How to divide data frame rows by number of columns in R?
- How to repeat a column of a data frame and join it with another data frame in R by rows?
- Remove rows from a data frame that exists in another data frame in R.
- How to convert rows in an R data frame to list?
- How to remove empty rows from an R data frame?