ggplot2 with loop

瀏覽次數:40 次
跳到第一則未讀訊息

Jua'

未讀,
2016年6月9日 下午4:10:342016/6/9
收件者:ggplot2
I'm working on this dataframe:

    Col0 <- c("AA", "BB", "CC", "DD","EE","FF")
    Col1 <- c(2,2,2,6,1,1)
    Col2 <- c(2,2,2,1,3,4)
    Col3 <- c(2,2,3,4,6,6)
    Col4 <- c(2,2,3,1,2,1)
    Col5 <- c(2,1,1,1,1,4)
    Col6 <- c(2,4,2,5,4,4)
    Col7 <- c(2,4,2,5,4,4)
    Col8 <- c(2,2,3,4,5,4)
    Col9 <- c(1,3,3,2,2,2)
    df<-data.frame(Col0,Col1,Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9)

And i created a plot using ggplot2

    Plot <- function(fun){
     
      df<-melt(fun,id =c("Col0"))
      colnames(df)[colnames(df) == 'value'] <- 'Val'
      colnames(df)[colnames(df) == 'variable'] <- 'Col_i'
      pl<- ggplot(df, aes(Col_i, Val, group=Col0)) + geom_line(aes(color=Col0))+theme(
        axis.text.x = element_text(angle = 90, hjust = 1))+ ggtitle(paste("Plot"))+  labs(color = "Letters")+ theme( panel.border = element_rect(colour = "black", fill=NA, size=1)) 
      print(pl)
    }
    Plotf <- Plot(df)

Starting from the assumption that the df can have n rows, i need to know how to print n graphs (one for each row) with one loop.

Hadley Wickham

未讀,
2016年6月9日 下午4:26:072016/6/9
收件者:Jua'、ggplot2
Have a look at http://rpubs.com/hadley/97970

Hadley
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ggplot2+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
http://hadley.nz
回覆所有人
回覆作者
轉寄
0 則新訊息