This is a test version of Biostars. For the public version, visit https://www.biostars.org.
graph boxplot error

I would like to plot a graph like this

enter image description here

but the graph is coming out like this

![enter image description here][2]

code

p1 <- ggplot(df, mapping = aes(x = FK_codonRNA , y=tscore,  fill = nomeOrganismo)) + 
  geom_boxplot() +
  facet_wrap(~nomeOrganismo)

df

![enter image description here][3]

size df ![enter image description here][4]

What am I doing wrong? How can I solve this problem?

r codon boxplot ggplot2

For starters, try switching to facet_grid, which gives you more control over the layout. Customizing ggplots is a step by step trial and error process (for me at least), so you may have to make changes one by one and experiment with different ways of making those changes.

In your case, you'd need a custom labeller (I think) and you'd also need to set the width of each box or the entire plot somehow.

in the absence of example data, try this:

data(iris)
library(ggplot2)
library(tidyr)
library(tools)

df=iris %>% 
    pivot_longer(-Species,names_to = "k", values_to = "v")

ggplot(df, aes(x=k,y=v, fill=Species))+
    geom_boxplot()+
    guides(x=guide_axis(angle = -45))+
    xlab("species")+
    ylab("Values")+
    theme_bw(base_size = 18) +
    theme(strip.text = element_text(hjust = 1, size=14),
          strip.background = element_blank(),
          strip.placement = "inside",
          legend.position = "")+
    facet_wrap(~Species,nrow = 3)

boxplot.png

0 answers

No answers yet.

Log in to answer this question.