In ggplot bar plot 2017 2018 2019(x axis limits) in that 2019 only have to be dynamic when the user change the date mentioned above

User searched from 01/01/2019 - 04/01/2019, selected Facility (All) and Providers (All). The query should search against all Facilities and Providers

In ggplot bar plot 2017 2018 2019(x axis limits) in that 2019 only have to be dynamic when the user change the date mentioned above

Please do the needful
dfPatientControl$Year <- format(strptime(df$RecordedDate, format = "%Y-%m-%d %H:%M:%S"), "%Y")
year <- dfPatientControl$Year
df <- data.frame(
rdate <- factor(year, levels = year),
percent <- c(dfPatientControl$PercentControl)
)

        df <- df[which(df$percent >= 0),]
        if(is.data.frame(df)){
            
            if(nrow(df) > 0){
                p <- ggplot(df,aes(x=rdate,y=percent, fill= factor(ifelse(percent>=70, "Above 70","Below 70"))))+
                    geom_bar(stat = "identity",width=0.9,colour = "black")+
                    geom_text(aes(label=paste0(prettyNum(percent, big.mark = ','), "%","(",dfPatientControl$TotalUnderControl,")")),size = 3, position = position_stack(vjust = 0.9), colour = "black")+
                    ggtitle("BP Control Comparison")+
                    xlab("Year") + ylab("Percent") +
                    labs(caption="Powered by  ®")+
                    coord_cartesian(ylim = c(20,100))+
                    scale_fill_manual(name = "Legend", values=c("Above 70"="forestgreen","Below 70"="firebrick3")) +
                    theme_classic()+
                    theme(
                        plot.title = element_text(color="black", size=14, face="bold"),
                        axis.text.x =element_text(size=14),
                        axis.text.y =element_text(size=14),
                        axis.title.x = element_text(size=14,face="bold"),
                        axis.title.y = element_text(size=14,face="bold"),
                        legend.text=element_text(size=14),
                        legend.title=element_text(size=14, face = "bold"),
                        panel.grid.major = element_blank(), #remove background box,color
                        panel.grid.minor = element_blank(),#remove background box,color
                        panel.background = element_blank(), #remove background box,color
                        axis.line = element_line(colour = "black"))
                
                p
            }
            else{
                showNotification("Please select different provider. No data available" , type = "message")
            }

This is my code
** In this df holds a variable "year" where it has values 2017,2018 and 2019. All are constant in barplot ggplot graph plot output. It shows no.of count for the whole year but 2019 alone has to be dynamic.. means when ever I change the date range, the count should differ according to the date..Is it possible**?

Hi, welcome!

We don't really have enough info to help you out. Could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.

If you've never heard of a reprex before, you might want to start by reading this FAQ:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.