Last Updated
Viewed 973 Times
        

I tried to make a boxplot today using ggplot2, and I encountered an error I haven't been able to solve, yet. I have used a similar approach (which I actually took from an answer by user @joran) before without incident, but I must be doing something incorrectly this time.

Here is my data:

myboxplot<-structure(list(gap = structure(1:2, .Label = c("Jib", "NoJib"), class = "factor"), Location = structure(c(4L, 4L), .Label = c("A", "B", "C", "D"), class = "factor"), min = c(21.809, 21.081), q1 = c(25.582, 25.375), med = c(28.082, 27), q3 = c(30.142, 28.622), max = c(37.166, 39.808), lab = c(2342L, 119681L)), .Names = c("JibStat", "Location", "min", "q1", "med", "q3", "max", "lab"), row.names = c(2L, 7L ), class = "data.frame")

The code that I have been attempting to use is as follows:

ggplot(myboxplot + aes(x=JibStat, fill=JibStat)) +
      geom_boxplot(aes(lower = q1, upper = q3, middle = med, ymin = min, ymax = max), stat = "identity")

and I get the following error message:

Error in Ops.data.frame(myboxplot, aes(x = JibStat, fill = JibStat)) : list of length 2 not meaningful

I have worked on resolving the issue, but I have not been able to find much on resolving the error. My Google skills must be lacking today, but I can't think of what to search for to get help on this problem. What is it I am doing wrong here?

Additional info: R version 3.0.1, 64-bit Windows 8.

I'm newbie at using ggplot2 with R. When I run this script

var<-schz.[1,]
values<-schz.[,-1]
ggplot(data=schz., aes(var, values)) + geom_boxplot()

I obtained this error message:

Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous. Error: Aesthetics must be either length 1 or the same as the data (80): x, y

The dataset is the following: [https://drive.google.com/file/d/0B7tO-O0lx79FZERvcHJUSmxNSTQ/view?usp=sharing]

Someone can tell me what's wrong? I understand it's something with the definition of x and y in the ggplot2 function, but I can't fix it!

Similar Question 2 : ggplot2 boxplot

I am trying to plot boxplot using ggplot2. sample data is like this.

> sampe

count genotype
71       mt
50       mt
71       mt
95       wt
60       mt
63       mt
75       mt
82       wt
93       wt
87       wt
61       mt
102       wt
60       mt
78       wt
78       wt
87       wt
84       wt
104       wt
81       wt
85       mt


> qplot(factor(genotype),count,data=sampe,geom="boxplot")

The above command produces plot like this: enter image description here

what's wrong here?? why is it plotting like this?? Even this below code produces same output.

ggplot(sampe,aes(x=factor(genotype),y=count))+geom_boxplot()

Similar Question 3 : Boxplot with ggplot2

I am working on a boxplot with forecast and observations which is quite long dataset. I am providing a sample format here.

> forecasts <- data.frame(f_type = c(rep("A", 9), rep("B", 9)), 
                          Date = c(rep(as.Date("2007-01-31"),3), rep(as.Date("2007-02-28"), 3), rep(as.Date("2007-03-31"), 3), rep(as.Date("2007-01-31"), 3), rep(as.Date("2007-02-28"), 3), rep(as.Date("2007-03-31"), 3)), 
                          value = c(10, 50, 60, 05, 90, 20, 30, 46, 39, 69, 82, 48, 65, 99, 75, 15 ,49, 27))
> 
> observation <- data.frame(Dt = c(as.Date("2007-01-31"), as.Date("2007-02-28"), as.Date("2007-03-31")), 
                            obs = c(30,49,57))

So far I have:

ggplot() + 
    geom_boxplot(data = forecasts,
                 aes(x = as.factor(Date), y = value, 
                     group = interaction(Date, f_type), fill = f_type)) +  
    geom_line(data = observations,
              aes(x = as.factor(Dt), y = obs, group = 1), 
              size = 2)

With this the box and whiskers are set by default. I want to assign these values so that I will know the extent of the whiskers. I have tried to pass a function with stat_summary with like:

f <- function(x) {
    r <- quantile(x, probs = c(0.05, 0.25, 0.5, 0.75, 0.95))
    names(r) <- c("ymin", "lower", "middle", "upper", "ymax")
    r
}

o <- function(x) {
    subset(x, x < quantile(x,probs = 0.05) | quantile(x,probs = 0.95) < x)
}

ggplot(forecasts, aes(x = as.factor(Date), y = value)) + 
    stat_summary(fun.data = f, geom = "boxplot", aes(group = interaction(Date, f_type), fill = f_type)) +
    stat_summary(fun.y = o, geom = "point") 

But, with this the groups are messed up. This produces stacked up plots. Does anyone how to accomplish this?

Similar Question 4 (3 solutions) : annotate boxplot in ggplot2

Similar Question 5 (1 solutions) : ggplot2 width of boxplot

Similar Question 6 (1 solutions) : Boxplot of table using ggplot2

Similar Question 7 (1 solutions) : Sorting a ggplot2 boxplot [duplicate]

Similar Question 8 (2 solutions) : Label boxes in ggplot2 boxplot

Similar Question 9 (1 solutions) : Boxplot of CSV data with ggplot2

cc