Question: Graph in R: sort alpha-numerically X-axis
0
gravatar for bdelolmo
2.5 years ago by
bdelolmo10
Barcelona
bdelolmo10 wrote:

Hello,

I am facing the problem to plot a typical CNV plot using R (and ggplot2), with ratios on the Y axis and the chromosome and position interval on the X-axis (e.g chr1:17000-17100) but I only get it sorted numerically by default. Do you know how could I do it?

cnv ggplot R • 940 views
ADD COMMENTlink modified 2.5 years ago • written 2.5 years ago by bdelolmo10

Not completely sure what you mean. Are the values "chr1:17000-17100" plotted like that in the x-axis? (in which case they would be considered factors and ordered by their order as factors. If that is the case then googling for something like "order factor ggplot2" may give you some hints (this is a commonly asked question). At any rate, I would suggest you add a minimum reproducible example so that people in this site can see what you get and give you an alternative.

ADD REPLYlink written 2.5 years ago by ddiez1.7k
0
gravatar for bdelolmo
2.5 years ago by
bdelolmo10
Barcelona
bdelolmo10 wrote:

@ddiez, Thanks for answering. My problem was that for example after chr1:17000-17000 being the last interval from that chromosome, it should follow chr2:xxx-yyy following an alphanumeric order, but I was getting chr10:xxx-yyy. By using factors I can handle this, as you say, so many thanks.

ADD COMMENTlink written 2.5 years ago by bdelolmo10

Please, add comments using the ADD COMMENT or ADD REPLY buttons above (instead of adding an answer). This helps keep conversations organized. Yes, what you explain looks exactly like the symptoms of using factors that follow a particular order. The searches I mentioned above should help you find a solution. Without the code you are using to obtain your plot it is not possible to go further.

ADD REPLYlink written 2.5 years ago by ddiez1.7k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 814 users visited in the last hour