unequal factor length issue

Greetings ,
I have the data frame below for an interaction. I want to create a bar plot with the data and when I create one I get the error message "Error in Variety:Dose : unequal factor lengths" which is said to be due to unequal factor lengths.How do i solve such a problem? I have tried merging but that does not work out

DATA FRAME:
Variety:Dose` avg_AB se

1 Akwa:25 54.2 1.75
2 Akwa:50 36.8 3.00
3 Akwa:75 42.8 3.25
4 Akwa:100 24.2 2.49
5 Anel:25 49.2 2.88
6 Anel:50 40.8 3.07
7 Anel:75 35 1.36
8 Anel:100 21.2 0.648
9 Kwarts:25 58.5 2.23
10 Kwarts:50 42.8 2.53
11 Kwarts:75 31 1.96
12 Kwarts:100 23 1.41
13 Selie:25 40.5 3.02
14 Selie:50 35 3.27
15 Selie:75 28.8 3.72
16 Selie:100 15.2 1.25

CODE:
library(ggplot2)
ggplot(MeanSE_AB, aes(x = Variety:Dose,
y = avg_AB,
fill = Dose))+
geom_bar(stat = "identity",
color = "black",
position = position_dodge(width=0.9))+
geom_errorbar(aes(ymax = avg_AB + se,
ymin = avg_AB - se),
position = position_dodge(width=0.9),
width = 0.25) +
labs(title = "",
x = "Variety",
y = "Germination Percentage (%)")+
geom_text(aes(x = Variety:Dose,
y = avg_AB + se,
label = as.matrix(ascend_AB$groups)),
position = position_dodge(width = 0.5),angle=90,
vjust = -(0.25))+theme_classic()

please use

dput(yourdata)

and please use markdown text.

"Markdown" can be achieved with the following great packages

Please also fill in what kind of diagram you need in the end.

It's not impossible to read it from the code, but it would be nice if you could add what you want the color gradient to be, what you want the horizontal axis to be, and which are the qualitative and quantitative variables.

Please provide the data.
Hypothetically, my opinion is that I believe that the column names in your data are causing the problem.

Hi ,

I could not attach data here it said file format not allowed. The graph requires is as in the uploaded pic which is actually an interaction bar graph.
dput(data) worked for me

thanks

I couldn't find "uploaded images".
Create a diagram with my imagination.

Is the following code helpful?

"." and ":" has a special meaning in R.
If it is in a column name, it will play tricks.

The column names will be modified by janitor::clean_names().


library(tidyverse)
library(janitor)

df <- read.table("clipboard")

head(df)
   Variety:Dose avg_AB    se
1       Akwa:25   54.2 1.750
2       Akwa:50   36.8 3.000
3       Akwa:75   42.8 3.250
df <- df %>% clean_names()

head(df)
   variety_dose avg_ab    se
1       Akwa:25   54.2 1.750
2       Akwa:50   36.8 3.000
3       Akwa:75   42.8 3.250
df %>%  ggplot(aes(x = variety_dose,
                      y = avg_ab))+
  geom_bar(stat = "identity",
           color = "black",
           position = position_dodge(width=0.9))+
  geom_errorbar(aes(ymax = avg_ab + se,
                    ymin = avg_ab - se),
                position = position_dodge(width=0.9),
                width = 0.25)+
  theme_classic()+
labs(title = "",
     x = "Variety",
     y = "Germination Percentage (%)")+
  # add my option
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

image

If you want to separate Variety and Dose, try using tidyr::separate().

df %>% separate(variety_dose,c("variety","dose"))

   variety dose avg_ab    se
1     Akwa   25   54.2 1.750
2     Akwa   50   36.8 3.000
3     Akwa   75   42.8 3.250

This topic was automatically closed 7 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.