Hello colleagues,
I am preparing a report in R markdown. To avoid repetitive coding, I am learning how to use functions to plot figures using ggplot().
First, I created a function;
{r, Helper functions}
##First function compares the population trend across genders
line_graph_gender <- function(data_new,xnew,ynew,titlenew,SEX,lwdnew,ylab)
{
line_graph_gender <- ggplot(data=data_new,aes(x=xnew,y=ynew,color=SEX))+
geom_line(lwd=lwdnew)+
labs(title=titlenew, y=ylab)
return (line_graph_gender)
}
Next, this function was called in a different chunk;
{r, ref.label="Helper functions"}
line_graph_gender(population_projected_gender,population_projected_gender$YEAR,
population_projected_gender$gender_pop,"Projected Population as Per Gender from
July 1, 2012 through July 1,2060",population_projected_gender$SEX,2,"Population
Percent")
In the Rstudio environment, we can see the figure. But, when we generate the HTML output, we don't see that figure in the HTML file.Can I kindly get advice/help in this context?
Help is appreciated.