Trying to plot GO in ggplot

New to R and still in the process of learning. Now, I am trying to plot GO in ggplot2 and need to separate the terms based on their category, so i tried the script below:

data <- read.csv("GO_Up.csv", sep =",", header = TRUE, stringsAsFactors = FALSE)

names(data) <- c("category", "ID", "term”, “count","pvalue")
names(data) <- c("category", "ID", "term", "count","pvalue")
S1<- ggplot(data, aes(x= count, y= reorder(term,- pvalue), size=count, color=p_value, group=count)) + geom_point(alpha = 0.8) + facet_wrap (~category)
S1 = S1+scale_color_gradient(low="red2", high="mediumblue", space="Lab",limit =c(0,0.1))
S1+theme(axis.text.x=element_text(family = "Tahoma+", size=8))

got a plot as below:
x-special/nautilus-clipboard
copy
file:///home/vrinda/Downloads/GO%20jumbled%20Yaxis.png.png

what I need is to have the terms based on the category on the y axis, but instead all the terms show up.
I need something that may look like the image below:
x-special/nautilus-clipboard
copy
file:///home/vrinda/Downloads/1642673545.39.png

How may I sort this in the script I have?
Need help urgently.

Thank you

s1

Hi Vrinda,

Welcome to RStudio Community! To properly help you, we'll need a reproducible example:

FAQ: What's a reproducible example (reprex) and how do I create one?

The easiest way to do this is provide the output to:

dput(your_data)

Or, if your data is very big:

dput(head(your_data, 200)) # replace 200 with an appropriate number

Furthermore, this doesn't look like a web link and looks more like something local to your computer. Is there an example online somewhere of the kind of plot you want? Or can you attach it to this post as an image?

If I had to have a go at fixing your issue without seeing your data or goal, I think replacing your facet call with this may help:

facet_wrap(~category, scales = "free_y")
1 Like

The attached image will be a reproducible example I am looking for to represent the data.

No, a reproducible example of your dataset data, because we don't have "GO_Up.csv".

I agree with Jack, please try this:

That looks like the use of facet_grid using scales = "free_y" and space = "free_y".

Hi,
Thank you
facet_wrap(~category, scales = "free_y")

this worked, I got the GO plot.

Thank you Jack. It helped me a lot.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.