ggplot2:几何区域未出现

时间:2019-03-04 08:30:38

标签: r ggplot2

几个月前,我使用脚本使用ggplot2构建堆积面积图。我现在正尝试使用类似的数据重新进行处理,但是我遇到了区域未显示的问题。在此之前,我检查了数据集是否可以绘制条形图。

def saveAsHadoopFile(
      path: String,
      keyClass: Class[_],
      valueClass: Class[_],
      outputFormatClass: Class[_ <: OutputFormat[_, _]],
      conf: JobConf = new JobConf(self.context.hadoopConfiguration),
      codec: Option[Class[_ <: CompressionCodec]] = None): Unit = self.withScope {

    val hadoopConf = conf
    hadoopConf.setOutputKeyClass(keyClass)
    hadoopConf.setOutputValueClass(valueClass)
    conf.setOutputFormat(outputFormatClass)
    for (c <- codec) {
      hadoopConf.setCompressMapOutput(true)
      hadoopConf.set("mapred.output.compress", "true")
      hadoopConf.setMapOutputCompressorClass(c)
      hadoopConf.set("mapred.output.compression.codec", c.getCanonicalName)
      hadoopConf.set("mapred.output.compression.type", CompressionType.BLOCK.toString)
    }

    if (conf.getOutputCommitter == null) {
      hadoopConf.setOutputCommitter(classOf[FileOutputCommitter])
    }

    val speculationEnabled = self.conf.getBoolean("spark.speculation", false)
    val outputCommitterClass = hadoopConf.get("mapred.output.committer.class", "")
    if (speculationEnabled && outputCommitterClass.contains("Direct")) {
      val warningMessage =
        s"$outputCommitterClass may be an output committer that writes data directly to " +
          "the final location. Because speculation is enabled, this output committer may " +
          "cause data loss (see the case in SPARK-10063). If possible, please use a output " +
          "committer that does not have this behavior (e.g. FileOutputCommitter)."
      logWarning(warningMessage)
    }

    FileOutputFormat.setOutputPath(hadoopConf,
      SparkHadoopWriter.createPathFromString(path, hadoopConf))
    saveAsHadoopDataset(hadoopConf)
  }

enter image description here

如您所见,没有出现区域。有什么建议吗?谢谢!

2 个答案:

答案 0 :(得分:1)

以下对heck1的评论, 我将字符名称替换为数字。我必须更改融化功能以使其正常运行。

library(ggplot2)
library(reshape2)
SampleID=c(1,2,3,4)
Species1=c(0.1,0.2,0.3,0.6)
Species2=c(0.15,0.25,0.35,0.4)
Species3=c(0.05,0,0.4,0.3)
Species4=c(0,0.05,0.05,0.9)
data=data.frame(SampleID,Species1,Species2,Species3,Species4)
mdata=melt(data,id.vars = "SampleID", measure.vars = c("Species1","Species2","Species3","Species4"))
mdata=as.data.frame(mdata)
ggplot(mdata, aes(x=SampleID, y=value,fill=variable,order=SampleID))+
geom_area(stat = 'identity',colour='black')

enter image description here

答案 1 :(得分:0)

为什么不使用geom_bar而不是geom_area

ggplot(mdata, aes(x=SampleID, y=value,fill=variable,order=SampleID))+
  geom_bar(stat = 'identity',colour='black')

产生

GGplot Barchart