Hi there,
I've been exploring and summarizing a dataset and I have a the financial position the original dataset contains 149 variables and approximately 50k observations.
Bellow the table output which I want to plot:
# tibble which represents the output of a larger dataset:
quarter_tbl2 <- tibble(
Quarters = c("2019.1", "2019.2", "2019.3", "2019.4", "2020.1"),
Tot.Income = currency(c("$10,566,152.63", "$8,722,398.82", "$8,851,412.04", "$6,066,070.54", "$1,209,047.17")),
Tot.Expense = currency(c("$9,335,033.37", "$7,755,142.94", "$7,961,638.86", "$5,252,027.79", "$986,271.78")),
Tot.Profit = currency(c( "$1,231,119.26", "$967,255.88", "$889,773.18", "$814,042.75","$222,775.39")),
Count = c("3025", "2871", "2675", "2082", "472")
)
str(quarter_tbl2)
# Tried geom_line() instead of geom_point(), geom_line() gave me no plot.
ggplot(data = quarter_tbl2) +
geom_point(aes(x= `Quarters`, y=`Tot.Income`), color ="Blue") +
geom_point(aes(x = `Quarters`, y= `Tot.Profit`), color = "purple") +
geom_point(aes(x = `Quarters`, y= `Tot.Expense`*-1), color = "Red") +
labs(
title = "Quarterly Total Expenses, Income & Proift",
y = "$"
) # +
#scale_y_continuous(labels = comma)
# noticed that even though the plot isn't exactly what I was going for, I tried
# adjusting the scale which resulted in something with no avail.
Initially I wanted to have the plot with 3 lines, Tot.Income, Tot.Profit on the same x, y axis and the cost as a secondary y axis as in MS Excel. Positive Y axist for the Total.Income & Tot.Profit on the left and then a secondary Y axis inverted (or not) with pretty scales for the Y axis.
Not online a line plot but I would like to understand how to approach the same as a bar graph as well since I believe the structure should be the same.
Something like this which I found online, althought could not understand the stat =
where the "identity" comes from.
# Create data
data <- data.frame(
name=c("A","B","C","D","E") ,
value=c(3,12,5,18,45)
)
# Barplot
ggplot(data, aes(x=name, y=value)) +
geom_bar(stat = "identity", width=0.2)
Any feedback or insight would be greatly appreciated.
Thank you for your time.
Best regards,
LF.