I wrote a code to plot a line graph showing total sales over time.
ggplot(data = total_sales_by_month_year, aes(x = month_year, y = total_sales)) +
geom_line() +
labs(title = "Total Sales by Month", x = "Month", y = "Total Sales")
it does, thanks. But i made this question as clear as possible so that i can get an answer, i'm currently on a project and the df is a subset of the df i am working with. Suppose you are working with a df that with columns date and total_amount_spent. I wrote a code that shows the total amount spent over then used the code to make a line plot. i kept on getting errors one of which is 'Do you need to adjust the group aesthetic'?. I would like to know what i am doing wrong and i would appreciate it if you can guide me.
The subset will plot in the same manner as the set if the arguments to aes are identical. But if you are adding a var and using it in aes not necessarily. So, show the subset data as modified because guessing is bootless.
The key to understand is that while numbers have a 'natural ordering' and, dates also are numbers with a natural ordering. character strings do not for the purpose of graphing. a representation of 'dates' in a textual form might look to you as a date, but not be a date class numeric object, and so it will not be clear that the x coords can be related straightforwardly to justify connecting the points into lines.
while your dput() contained a data.frame with actual numeric date types, your opening post shows that you likely had a 'date appearing' textual type. at some point you did a conversion; but you havent considered that this is the reason for your initial lack of a line, and the post example shared ability to see a line.
yes, i made a conversion. i created a new column that contains the month and year (eg Jan 2018)from the date column (eg 01-01-2018) in my df. the new column's data type is chr. trying to make a line plot using this column doesnt work. what should i do ?