My dataset example looks like this:
dput(t)
structure(list(date = structure(c(19091, 19091, 19092, 19092,
19093, 19093, 19094, 19094, 19095, 19095, 19096, 19096, 19097,
19097, 19098, 19098, 19099, 19099, 19100, 19100, 19101, 19101,
19102, 19102, 19103, 19103, 19104, 19104, 19105, 19105, 19106,
19106, 19107, 19107, 19109, 19109, 19110, 19110, 19111, 19111,
19112, 19112, 19113, 19113, 19114, 19114), class = "Date"), TempAmb_Avg = c(13.16,
13.16, 7.929, 7.929, 12.29, 12.29, 10.37, 10.37, 10.91, 10.91,
10.14, 10.14, 9.15, 9.15, 11.25, 11.25, 9.17, 9.17, 11.94, 11.94,
11.26, 11.26, 9.45, 9.45, 9.09, 9.09, NA, NA, 6.447, 6.447, 9.14,
9.14, 8.02, 8.02, 10.54, 10.54, 10.12, 10.12, 11.56, 11.56, 12.3,
12.3, 10.82, 10.82, 11.17, 11.17)), row.names = c(NA, 46L), class = "data.frame")
I'm having a problem that I can't go around. When plotting the TempAmb_Avg geom_bar does not display the real data, but geom_line, displays. I've been using this code:
plot<- ggplot(NDVI)
geom_bar(aes(x=date, y=TempAmb_Avg),stat="identity",colour="blue")
geom_line(aes(x=date, y=TempAmb_Avg),stat="identity",colour="black")
labs(x="TIME",y="TºC")
theme_bw()
plot
What do I have to do to display the real data with geom_bar?
I've found a solution but I'm lacking one step. To avoid TempAmb_Avg data duplication when using geom_bar I've divided TempAmb_Avg/2.
plot<- ggplot(NDVI)
geom_bar(aes(x=date, y=TempAmb_Avg/2),stat="identity",colour="blue")
geom_line(aes(x=date, y=TempAmb_Avg),stat="identity",colour="black")
labs(x="TIME",y="TºC")
theme_bw()
plot
However not all TempAmb_Avg is duplicated. How can I set a condition to only divide with 2 the duplicated values?
CodePudding user response:
You could try
library(dplyr)
library(ggplot2)
#load your data first to NDVI object
plot <- NDVI %>%
#this will delete any duplicate row
distinct() %>%
ggplot(NDVI)
geom_bar(aes(x=date, y=TempAmb_Avg),stat="identity",colour="blue")
geom_line(aes(x=date, y=TempAmb_Avg),stat="identity",colour="black")
labs(x="TIME",y="TºC")
theme_bw()
plot
CodePudding user response:
Just delete the duplicated data of the column TempAmb_Avg and then plot with geom_bar
.