Rshiny - ggplot - density plot
1
0
Entering edit mode
3 months ago

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

histogram Rshiny ggplot R • 584 views
ADD COMMENT
0
Entering edit mode

var is a reserved keyword in the stats library, don't use it

ADD REPLY
0
Entering edit mode

Hey Jeremy, thanks for your input. I changed it to var_col, it still gives the same error.

ADD REPLY
0
Entering edit mode

put your rshiny project up on a github site so we can reproduce the problem

ADD REPLY
1
Entering edit mode

I have added the input files and code to my git. I have used aes_string to overcome the above issue, but I'm still not sure how to do a errorbar(issue with ymax and ymin).

https://github.com/vinishavenugopal/Rshiny

Please take a look. I get an error while generating errorbar.

ADD REPLY
1
Entering edit mode
3 months ago
komal.rathi ★ 3.9k

You are trying to merge on a column that does not exist in your metadata file.

The full metadata has no ExternalSampleId as well, in fact I don't see any column that can be merged with your expression data columns. You will need to format your Quote column or format the columns of your expression data to match them up.

ADD COMMENT
0
Entering edit mode

Sorry I had to edit the metadata file due to privacy concerns. I edited the files in the git, now if you can see the barplot function, it works completely fine if I don't add the errorbar. The issue is the getting the mean of var1 to be used in the ymin and ymax of errorbar. I appreciate your help. Thanks!

ADD REPLY

Login before adding your answer.

Traffic: 2147 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6