I have a dataframe of tempratures where each column represents a year from 1996 to 2015 and rows are data from 1-Jul to Oct-31:
head(df)
[![Dataframe head][1]][1]
I am trying to create a line plot with x= DAYS and y=temp per year. when I use DAYS in the loop, either with aes() or aes_strint() it doesn't produce anything:
iterator <- c(colnames(df))[-1]
g <- ggplot(df, aes_string(x = 'DAY'))
for (i in iterator){
g <- g+ geom_line(aes_string(y=i))
}
print(g)
so I added an index column which is just integers from 1 to 123. Now the same code plots a bunch of lines but very strange:
df$index <- c(1:123)
iterator <- c(colnames(df))[-1]
iterator <- iterator[-21]
g <- ggplot(df, aes_string(x = 'index'))
for (i in iterator){
g <- g+ geom_line(aes_string(y=i))
}
print(g)
[![Final plot][2]][2]
as you can see, I have one line per column name and all the Colum names are stacking above each other. This has compressed the vertical axis so much that the variations in temperature is not visible. I wish my y-axis just goes from 50 to 100 and there will be one line per column name there with the same scale as other columns. How do I do that? [1]: https://i.sstatic.net/ruF11.png [2]: https://i.sstatic.net/gAvMe.png
