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

I would like to plot a graph like this

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
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.

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)