1

I have a data frame and I would like to stack the points that have overlaps exactly on top of each other.

here is my example data:

value <- c(1.080251e-04, 1.708859e-01, 1.232473e-05, 4.519876e-03,2.914256e-01, 5.869711e-03, 2.196347e-01,4.124873e-01, 5.914052e-03, 2.305623e-03, 1.439013e-01, 5.407597e-03, 7.530298e-02, 7.746897e-03)
names = letters[1:7]
data <- data.frame(names = rep(names,), group = group, value = value, stringsAsFactors = T)
group <- c(rep("AA", 7) , rep("BB", 7))

I am using the following command:

p <- ggplot(data, aes(x = names, y = "", color = group)) + 
geom_point(aes(size = -log(value)), position = "stack") 
plot(p)

But the stacked circle outlines out of the grid. I want it close or exactly next to the bottom circle. do you have any idea how I can fix the issue?

Thanks, enter image description here

2
  • Try aes(y = 1... and then set new y limits: ylim(1,2). If this is not working, please provide a reproducible example of your dataset (stackoverflow.com/questions/5963269/…) Commented Mar 1, 2020 at 1:56
  • Thanks for your response! It did not work. I have edited my question. Can you please take a look at it? Commented Mar 1, 2020 at 2:21

1 Answer 1

4

The y-axis has no numeric value, so use the group instead. And we don't need the color legend now since the group labels are shown on the y-axis.

ggplot(data, aes(x = names, y = group, color = group)) + 
  geom_point(aes(size = -log(value))) +
  guides(color=FALSE)

enter image description here

Sign up to request clarification or add additional context in comments.

6 Comments

Thats a good idea too. Do you know how can I decrease the distance between vertical lines. I want the circles of two groups to be closer to each other.
After producing the graph, reduce the height of the device manually. Or when saving to a file, tinker with the height argument in the ggsave function. For example, ggsave("figure1.png", height=2, width=4). See my edited graph.
Thanks for your reply. It was really helpful. Using ggsave() reduces the hight of my figure But not as much as I want. Do you know any other way that I can play with the horizontal lines to reduce the distance between them?
You want the dots closer together, almost touching?
Maybe you can increase the size of the points: + scale_size_continuous(range=c(3,10)) and/or add more discrete categories to the y-axis: + ylim("","AA","BB","")
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.