boxplot is not ok

Hi, can anybody help me with my boxplot. Why the SPI 9 is divided it should be only SPI3 SPI6 SPI 9 and SPI12, not SPI 9 SPI 9

Rplot

I suspect you have leading and/or trailing spaces in some instances of SPI 9. You can use the unique() function to list the different values in a column.

1 Like

Would you ming posting you R code?
That would simplify investigation.

Hi, the problem is solved but can you help me, how can i rearrange the position of plot, i mean it should be SPI3, SPI6, SPI9 and SPI12 but the SPI12 comes out first.

Rplot01

df.m <- melt(testtukui, id.var = "MONTH")
ggplot(data = df.m, aes(x=variable, y=value)) + geom_boxplot(aes(fill=MONTH)) + ylab("SPI") + xlab(NULL)

this is my script.

and my data is like:

|MONTH|MODERATE|
|SPI3|-1.32|
|SPI3|-1.25|
|SPI3|-1.09|
|SPI3|-1.02|
|SPI3|-1.15|
|SPI3|-1.40|
|SPI6|-1.11|
|SPI6|-1.43|
|SPI9|-1.21|
|SPI9|-1.18|
|SPI12|-1.16|
|SPI12|-1.24|

You can force the order of the x axis categories by using the factor() function.

df.m$MONTH <- factor(df.m$MONTH, levels = c("SPI3", "SPI6", "SPI9", "SPI12"))

Another alternative to @FJCC's suggestion may be to use "%>% select()" before "melt".
Example:
testtukui <- testtukui %>% select(MONTH, SPI3, SPI6, SPI9, SPI12)

Hi. I need help. Why I get

Error in $<-.data.frame(*tmp*, MONTH, value = integer(0)) :
replacement has 0 rows, data has 6027

hi. it says

could not find function "%>%"

why is that? :frowning:

The pipe %>% is part of the magrittr package. You have to load either that package or the dplyr package that will import magrittr. Use

library(magrittr)
#or
library(dplyr)

For your other error, please show your code or, better, a reproducible example.

2 Likes

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.