glihm
glihm

Reputation: 1246

Extend X axis interval ggplot2

I am trying to plot data with lot's of X axis values. I am trying to not overlap my point with geom_point. I found lot's of discussions about "scale_x_continuous", "position = jitter or dodge" etc... and every time my problem is remaining because I need to keep my point aligned. Moreover, "scale_size_area" does not make it good.

EDIT: Generated data already melted at the end of the post.

I can not post image (Link to image), but to give the idea: I have 6 levels in my Y axis, and 400 levels in X axis. My points (shape = 1 = circle) are Y-levels aligned, and have different diameters depending on the value.

This is ok, but circles are overlapping.

plot <- ggplot(data, aes(x_variable_400_levels, y_variable_6_levels)) + 

        # value*100 because values are between 0 and 1 to have bigger circles
        geom_point(shape = 1, size = data$value*100) +

        # theme description
        theme(
              plot.title = element_text(lineheight=.8, face="bold", vjust=1),
              axis.title.x = element_text(vjust=-0.5),
              axis.title.y = element_text(vjust=0.3)
        )

So, my question is: Can I modify the interval between two values of the X axis in order to avoid the overlapping between circles? Jitter is not interesting here because the noise does not allow a good visualisation of data, including that when I tried to had only HORIZONTAL noise.

Any kind of solution, links or other tutorial to solve it will be appreciated.

EDIT : Generated data. Import with read.table, sep = "," and header = T. The point is that, I have very little circles and they are important too.

data <- read.table(text='"trf","sample","value"
                   36,"S1",0.143882104
                   38,"S1",0.025971979
                   47,"S1",0.016711593
                   56,"S1",0.027896069
                   67,"S1",0.025870577
                   93,"S1",0.07638307
                   100,"S1",0.022905895
                   102,"S1",0.019192547
                   104,"S1",0.018258923
                   107,"S1",0.005032219
                   114,"S1",0.028297368
                   123,"S1",0.007874848
                   131,"S1",0.024184004
                   36,"S2",0.115123666
                   38,"S2",0
                   47,"S2",0.00479275
                   56,"S2",0.029523128
                   67,"S2",0.030133055
                   93,"S2",0.044749246
                   100,"S2",0.032865979
                   102,"S2",0
                   104,"S2",0
                   107,"S2",0.013160255
                   114,"S2",0.052047248
                   123,"S2",0.007632445
                   131,"S2",0
                   36,"S3",0.179332128
                   38,"S3",0.046215267
                   47,"S3",0
                   56,"S3",0.070791832
                   67,"S3",0.050214857
                   93,"S3",0.074108014
                   100,"S3",0
                   102,"S3",0
                   104,"S3",0
                   107,"S3",0
                   114,"S3",0.081441849
                   123,"S3",0
                   131,"S3",0.100090456', header=T,sep=",")

Upvotes: 0

Views: 1409

Answers (1)

Heroka
Heroka

Reputation: 13149

I don't think changing the interval is the solution, as your x-axis is numeric. It would be more difficult to interpret if the space between for instance 1 and 2 is larger that the space between 9 and 10. And if you would change all intervals to the largest circle, the plot would be too wide. I also imagine it would be very cluttered if you have more data, which makes it harder to see patterns. Maybe a (faceted) barplot is the solution? Allows for horizontal and vertical comparison, small values are visible and values are easily extracted and compared. Here's a start:

p2 <- ggplot(data, aes(x=trf, y=value))+
  geom_bar(stat="identity") +
  facet_grid(sample~.) +
  xlim(c(0,150)) + theme_bw()

enter image description here

Upvotes: 1

Related Questions