首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么在R strip.position = "top“中使用饼图中的面不起作用?

为什么在R strip.position = "top“中使用饼图中的面不起作用?
EN

Stack Overflow用户
提问于 2018-06-19 15:27:49
回答 1查看 145关注 0票数 1
代码语言:javascript
运行
复制
library(ggplot2)
library(reshape2)
library(plyr)

y  = data.frame(category=c(1,1,1,1,2,2,2,2), value=c(2,2,1,1,2,2,2,1))

# get counts and melt it
data.m = melt(table(y)) 
names(data.m)[3] = "count"

# calculate percentage:
m1 = ddply(data.m, .(category), summarize, ratio = count / sum(count))

#order data frame (needed to comply with percentage column):
m2 = data.m[order(data.m$category),]

# combine them:
mydf = data.frame(m2,ratio=m1$ratio)

# get positions of percentage labels:
mydf = ddply(mydf, .(category), transform, position = cumsum(count) - 0.5*count) 

# create bar plot
pie = ggplot(mydf, aes(x = factor(1), y = count, fill = as.factor(value))) +
      geom_bar(stat = "identity", width = 1) +
      facet_wrap(~category, strip.position = "top")

# make a pie
pie = pie + coord_polar(theta = "y")

# add labels
pie + geom_text(aes(label = sprintf("%1.2f%%", 100*ratio), y = position))

Strip.positon = "top"不工作。为什么会发生这种情况?此外,"bottom"不工作,但"left""right"工作正常。

EN

Stack Overflow用户

发布于 2018-06-19 16:37:03

我看不出代码有什么问题。它工作得非常好。

  1. Top

  1. Bottom

  1. Left

  1. Right

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50922805

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档