Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot Error: Don't know how to automatically pick scale for object of type function

I plotted a stacked bar graph in R using ggplot2 package,

 data<-read.table("K.txt",header=TRUE, sep="\t")
> data
  Sample   P1   P2   P3   P4
1     G1 0.02 0.01 0.03 0.95
2     G2 0.01 0.01 0.02 0.97
3     G3 0.01 0.01 0.02 0.97
4     G4 0.01 0.01 0.02 0.97
5     G5 0.01 0.01 0.02 0.96
6     G6 0.01 0.01 0.01 0.98
7     G7 0.05 0.01 0.01 0.93
8     G8 0.34 0.01 0.01 0.64
9     G9 0.43 0.01 0.01 0.56
> library("reshape2", lib.loc="C:/Program Files/R/R-2.15.2/library")
> data1<-melt(data)
Using Sample as id variables
> head(data1)
   Sample variable value
1      G1       P1  0.02
2      G2       P1  0.01
3      G3       P1  0.01
4      G4       P1  0.01
5      G5       P1  0.01
> library("ggplot2", lib.loc="C:/Program Files/R/R-2.15.2/library")
ggplot(data=data1, aes(x=sample, y=value, fill=variable))+geom_bar(width=1)+scale_y_continuous(expand = c(0,0))+ opts(axis.text.x=theme_text(angle=90))
Don't know how to automatically pick scale for object of type function. Defaulting to continuous
Error in data.frame(x = function (x, size, replace = FALSE, prob = NULL)  : 
  arguments imply differing number of rows: 0, 36

Can any1 help me to sort out this error?

Many thanks Ramesh

like image 903
ramesh Avatar asked Feb 27 '14 03:02

ramesh


People also ask

What does Ggplot function do?

ggplot2 is a plotting package that provides helpful commands to create complex plots from data in a data frame. It provides a more programmatic interface for specifying what variables to plot, how they are displayed, and general visual properties.

What is After_stat?

after_stat. An aesthetic expression using variables calculated by the stat. after_scale. An aesthetic expression using layer aesthetics.

What does Geom_point () do in R?

The function geom_point() adds a layer of points to your plot, which creates a scatterplot. ggplot2 comes with many geom functions that each add a different type of layer to a plot.


1 Answers

Change sample (built-in function) to Sample (your variable)

ggplot(data=data1, aes(x=Sample, y=value, fill=variable)) +
    geom_bar(width=1) +
    scale_y_continuous(expand = c(0,0)) +
    opts(axis.text.x=theme_text(angle=90))
like image 159
Ananta Avatar answered Sep 28 '22 00:09

Ananta