I'm trying to recreate a graph I made in excel, using ggplot2 in R and I'm having some trouble.
My variable 1 is a continuous variable (prices) and my variable two is a discrete one (cashflows)- both plotted against the same time steps.
As you noticed one variable is plotted using bars and the other using a line.
Is there any way someone could give me some help using random values? I was only able to plot them as lines.
In the sample code below v1 is the prices, v2 is the cashflows, and time is a seq(1:270)
gdata = data.frame(num = time, prices=v2, cashflows = v3)
test_data <- melt(gdata, id="num")
ggplot(data=test_data, aes(x=num, y=value, colour=variable)) +
geom_line() +
ggtitle("Prices") +
labs(x="Time",y="Prices") + theme_grey(base_size = 14) + theme(legend.title=element_blank())