I'm working on this df
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 using facet I created a graph
library(ggplot2)
library(tidyr)
pl<-df %>%
gather(Hi, Val, -Col0) %>%
ggplot(aes(Hi, Val, group = Col0, col = Col0)) + facet_grid(Col0 ~ .)
pl<- pl + geom_line() +theme(
axis.text.x = element_text(angle = 90, hjust = 1))+ theme( panel.border = element_rect(colour = "black", fill=NA, size=1),legend.direction ="vertical",legend.position = "right")+guides(fill=guide_legend(ncol=1))+scale_y_continuous(labels=comma) +theme(legend.text = element_text(size=6))
print(pl)
The question is is possible instead of using Col0
pass to the functions the value:
value<- names(df[1])
Because i"m working on a lot of df and i'd like to generalize the function