I'm trying to plot a chart with ggplot. In this graph I try to give an idea of the density of consumer sentiment (which can be classified as positive, negative and neutral) in relation to the price. Now I would like to try to connect all these points (red in case of negative feeling, green in case of positive feeling and gray in case of neutral feeling) between them in chronological order with the command geom_line().
ggplot(test, aes(x=date, y=price, color=as.factor(tot_sentiment))) +
geom_point(size= abs(test$Sentiment)) +
scale_shape_manual(values=c(19, 19, 19)) +
scale_color_manual(values=c('#FF0C00','#999999', '#04C200')) +
theme(legend.position="top") +
scale_x_date(date_labels="%d %b %y",date_breaks ="1 week") +
xlab("Time") + ylab("Price") + labs(color='Legenda:') + geom_line()
Unfortunately, it connects only the points of the same sentiment and not all the points in chronological order as I wish. I also tried +geom_line(aes(group = tot_sentiment))
with no results
expected output:
MY DATA:
structure(list(date = structure(c(17511, 17512, 17513, 17514,
17515, 17516, 17517, 17518, 17519, 17520, 17521, 17522, 17523,
17524, 17525, 17526, 17527, 17528), class = "Date"), price = c(16936.8,
17415.4, 16408.2, 16564, 17706.9, 19497.4, 19140.8, 19114.2,
17776.7, 16624.6, 15802.9, 13831.8, 14699.2, 13925.8, 14026.6,
16099.8, 15838.5, 14606.5), Sentiment = c(0L, -2L, -13L, 4L,
-6L, 1L, -2L, -1L, -3L, 2L, -4L, -6L, 0L, 4L, 1L, 6L, 5L, 7L),
tot_sentiment = c("neutral", "negative", "negative", "positive",
"negative", "positive", "negative", "negative", "negative",
"positive", "negative", "negative", "neutral", "positive",
"positive", "positive", "positive", "positive")), row.names = c(NA,
-18L), .internal.selfref = <pointer: 0x000002388fc21ef0>, class = c("tbl_df",
"tbl", "data.frame"))