Hi everyone,
I have this list of dataframe:
I would like to please create a histogram like this for each of the dataframes with the name of the dataframe as the title:
I used this code to create the histogram
library(ggplot2)
p = qplot(india$Natems_Agri_Unit_2_01.05.2019, geom="histogram", binwidth = 0.5, main = "Histogram of Crop Height for Unit 1 08.04.2019", fill=I("red"),
col=I("blue"), xlab = "Crop Height of Natems Agri Unit_1_08.04.2019", ylab = "Count Frequency")
p + theme_bw() # Black and white theme
What I have tried so far:
library(ggplot2)
result = list()
for(i in c(1:91))
{
p = qplot(india[[i]], geom="histogram", binwidth = 0.5, main = "Histogram of Crop Height for Unit 1 08.04.2019", fill=I("red"),
col=I("blue"), xlab = "Crop Height of Natems Agri Unit_1_08.04.2019", ylab = "Count Frequency")
result[[i]]=p
print(p)
}
How can I fix this please?
Many Thanks,
Ishack
We need to use print within forloop:
Thank you! I've edited the answer.
Thanks very much! One more thing if you don't mind please, how do I export each plot as a png with the filename the same as
names(india)[i])
?The code only plots the last item in the list. How can i fix this please?
Could this be the problem?
This is my first time doing this, so If you could help, that would be greatly appreciated
In the below code I've added a
png
command before theprint
command.The
paste
command will concatenate thenames(india)[i]
, and the letterspng
which are separated by a.