ggplot / ally boxplots使用for循环

时间:2015-11-09 02:30:07

标签: r loops ggplot2 boxplot ggally

我正在尝试绘制ggplot矩阵,框图版本工作得很好,但是当我尝试用ggplot做同样的事情时我很失败

boxplot版本:

public class JsonNetResult : JsonResult
{
    public JsonNetResult()
    {
        Settings = new JsonSerializerSettings
        {
            ReferenceLoopHandling = ReferenceLoopHandling.Error
        };
    }

    public JsonSerializerSettings Settings { get; private set; }

    public override void ExecuteResult(ControllerContext context)
    {
        if (this.Data != null)
        {
            if (context == null)
                throw new ArgumentNullException("context");
            if (this.JsonRequestBehavior == JsonRequestBehavior.DenyGet && string.Equals(context.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
                throw new InvalidOperationException("JSON GET is not allowed");

            HttpResponseBase response = context.HttpContext.Response;
            response.ContentType = string.IsNullOrEmpty(this.ContentType) ? "application/json" : this.ContentType;

            if (this.ContentEncoding != null)
                response.ContentEncoding = this.ContentEncoding;


            var scriptSerializer = JsonSerializer.Create(this.Settings);

            using (var sw = new StringWriter())
            {
                    scriptSerializer.Serialize(sw, this.Data);
                    //outofmemory exception is happening here
                    response.Write(sw.ToString());
            }
        }
    }
}

箱形图版本的结果: enter image description here

ggplot版本:

$opts = array(
  'method' => "GET",
  'https'=>array(
    'header'=>"Accept-language: en\r\n"
  )
);

$context = stream_context_create($opts);

$homepage = file_get_contents('https://www.bing.com/news/search?q=cars&form=YFNR&format=RSS', false, $context);

我认为不应该那么困难,但我被困住了。

谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

经过一段时间的努力,虽然这是一种痛苦的方法来添加所有这些情节[[i]]。谢谢你的帮助。

plots = NULL
for (scale in c("POMS",
                "POMS_post",
                "DERS",
                "DERS_post",
                "REAPPRAISAL",
                "REAPPRAISAL_POST",
                "NEGATIV",
                "NEGATIVE_POST")) {
        plots[[scale]] = ggally_box(kata1, aes_string("Skupina", scale, color = "Skupina"), 
                                    outlier.colour = "red",
                                    outlier.shape = 13)
        }

grid.arrange(plots[[1]],plots[[2]],
             plots[[3]],plots[[4]],
             plots[[5]],plots[[6]],
             plots[[7]],plots[[8]], ncol = 2)