graph boxplot error
0
0
Entering edit mode
5 months ago
USER • 0

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 • 390 views
ADD COMMENT
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 2444 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6