Arrange plot in order based on custom user input ggplot2

I am taking a custom user input and trying to plot a bar graph in shiny. Is there a way to reorder the graph based on custom user input? Here is the code:

ggplot(head(initial_data_ip_analysis, 10), aes(reorder(ip_address, -opex), opex)) + geom_bar(stat = "identity",  fill="steelblue",
                                                                            color="black", position=position_dodge()) +  
theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)) + scale_y_continuous(labels = comma) + 
geom_text(aes(label=opex), position=position_dodge(width=0.5), vjust=-0.25, size = 3) + xlab("ip_address") 

In the code ip_address and opex are specific columns in the df, I want the ip_address to be a custom user input. So instead of hardcoded ip_address it could be anything like ip_location or ip_domain but at the same time opex stays constant since it will be fixed in my case. Sample plot:enter image description here



comments powered by Disqus