简体   繁体   中英

How to plot this type of matrix in R

i have this matrix

     CL r1 r2 r3 r4 r5 r6 
[1,] 25  0  1  0  0  1  0  
[2,] 30  5  3  1  1  1  1  
[3,] 35  1  0  1  0  0  1  
[4,] 40  0  0  0  0  0  0  

I would like plot it in this manner (from excel example)

在此处输入图片说明

and

在此处输入图片说明

I can do it with ggplot2 ? or with other package?

For your 2nd plot :

library(reshape2)
library(ggplot2)

df_series<-as.data.frame(matrix_series)
colnames(df_series)<-c("CL", "Series1","Series2","Series3","Series4","Series5", "Series6")
df_series.tall<-melt(df_series, id.vars="CL")
ggplot(df_series.tall, aes(x=CL,y=value, color=variable))+geom_smooth()

For the 1st plot :

ggplot(df_series.tall, aes(x=variable,y=value, fill=factor(CL)))+geom_bar(stat="identity", position="dodge")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM