Rshiny – ggplot – density plot

Hi,

I’m trying to do a density plot in Rshiny. I find it confusing with this error

Error: StatBin requires a continuous x variable: the x variable is discrete.Perhaps you want stat=”count”?

My data looks like: t_data_gene

            ENSG
S45        545
S43        4588
S36        454
S33        4685 
...

I used:

ggplot(t_data_gene, aes(x=ENSG)) + 
      geom_histogram(aes(y=..density..),binwidth=100, colour="black", fill="salmon1")+
      geom_density(alpha=.2)

densityplot

This works fine but I assign ENSG to a variable var inside output function of Rshiny

ggplot(t_data_gene, aes(x=var)) + 
      geom_histogram(aes(y=..density..),binwidth=100, colour="black", fill="salmon1")+
      geom_density(alpha=.2)

I get the above error. Why is that and how do I resolve this? I tried using stat=count but it gives me a different plot.

ggplot(t_data_gene, aes(x=var)) + geom_bar()
density_stat

Read more here: Source link