ggplot错误:不知道如何为类型函数的对象自动选择比例 [英] ggplot Error: Don't know how to automatically pick scale for object of type function

查看:1934
本文介绍了ggplot错误:不知道如何为类型函数的对象自动选择比例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ggplot2包在R中绘制了一个堆叠的条形图,

  data< -read.table(K.txt ,header = TRUE,sep =\ t)
>数据
样本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
>库(reshape2,lib.loc =C:/ Program Files / R / R-2.15.2 / library)
> data1< -melt(data)
使用Sample作为id变量
>头(data1)
样本变量值
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
>库(ggplot2,lib.loc =C:/ Program Files / R / R-2.15.2 / library)
ggplot(data = data1,aes(x = sample,y = value,fill =变量))+ geom_bar(width = 1)+ scale_y_continuous(expand = c(0,0))+ opts(axis.text.x = theme_text(angle = 90))
不知道如何自动选择规模为功能类型的对象。默认为连续
data.frame中的错误(x = function(x,size,replace = FALSE,prob = NULL):
参数意味着行数不同:0,36

可以使用any1来解决这个错误吗?

非常感谢
Ramesh

解决方案

更改 sample )到样本(您的变量)

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


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

解决方案

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

这篇关于ggplot错误:不知道如何为类型函数的对象自动选择比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆