Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 185790
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 10, 20222022-06-10T07:01:43+00:00 2022-06-10T07:01:43+00:00

r – subset x axis when using facet_wrap

  • 0

[ad_1]

Possibly this question has been asked before but I don’t manage to find a solution.
I have a TSV (test.tsv) that looks like this:

TPM variants    NOI_ID  HLA NAL
324.28  several p1  one 2
169.21  NA  p1  two 15
154.78  NA  p1  three   0
143.31  NA  p1  four    2
468.7   NA  p2  five    0
322.76  several p2  six 2
620.98  NA  p2  two 0
591.17  NA  p2  seven   0
637.74  NA  p3  eight   4
519.8   NA  p3  nine    10
1439.58 NA  p3  ten 23
122.05  NA  p4  five    14
149.74  NA  p4  eleven  77
213.7   NA  p4  twelve  100
162.53  NA  p4  one 15

Using this code:

fig13 <- read.table("test.tsv", sep="\t", header=T, check.names=FALSE)
fig13 = fig13[-which(grepl("_w8", fig13$NOI_ID)),]
fig13_melt <- melt(fig13[c("TPM", "NOI_ID", "HLA", "variants")], id=c("NOI_ID", "HLA", "variants"))

hla_barplot = ggplot(fig13_melt, aes(x=1:nrow(fig13_melt), y=value, fill=variants)) +
     geom_bar(stat="identity", position="dodge") + ggtitle("HLA status", subtitle = "all samples") + theme_bw() +
     theme(axis.title.y=element_blank(), axis.title.x=element_blank(), 
           plot.title = element_text(face = "bold", size = 15, hjust = 0.5),
           plot.subtitle=element_text(size=12, hjust=0.5, face="italic"),
           axis.text.y = element_text(size=6),
           axis.text.x = element_text(angle = 90, hjust=1, size=6)) +
     geom_text(aes(label = round(value,0), vjust = 1, size = 1)) +
     scale_x_discrete(labels=fig13_melt$HLA, breaks=1:nrow(fig13_melt), limits=factor(1:nrow(fig13_melt)), name="HLA")
hla_barplot

I can plot the following:
enter image description here

However when I try to use facet_wrap to split the plot:

hla_barplot + facet_wrap(.~ NOI_ID, nrow = 1)

I get the following:

enter image description here

So, as far as I can see, each subplot has all the x labels of the whole dataset. Is there a way to just plot in the x-axis the labels of each subgroup?

[ad_2]

  • 0 0 Answers
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 325 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 295 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 292 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.