with a dataframe df
like below, Im trying to create a line chart for one of the parameters - Income
- in the real data there are other parameters.
text <- "
Parameter,Company, Qtr, Value
Income, Comp1, Q1FY18, 100
Income, Comp1, Q2FY18, 110
Income, Comp1, Q3FY18, 130
Income, Comp2, Q1FY18, 60
Income, Comp2, Q2FY18, 70
Income, Comp2, Q3FY18, 90
"
df <- read.table(textConnection(text), sep=",", header = T,
stringsAsFactors = F)
I created a function such that I can re-use this - the function takes a dataframe and set of metrics and plot them
plotMetricsLine <- function(df, metrics) {
df <- df %>%
filter(Parameter %in% metrics)
p <- ggplot(data=df, aes(x=Qtr, y=Value,color = Company)) +
geom_line(size=1)
return(p)
}
When I'm using that function by calling plotMetricsLine(df, "Income")
- it is giving an empty plot as in the picture below. What is going on wrong here ?