S********a 发帖数: 359 | 1 hsize, vsize, horigin, vorigin 这些数取什么值,才能使四个图在同一页里呢?要
生成四个pie chart,存PDF在同一页里,谢谢
goptions reset=all device=pdfc ;
ods pdf file="c:\pie.pdf" startpage=never;
goptions hsize=5.20in vsize=3.75in;
proc gchart data=pie;
goptions horigin=0in vorigin=0in;
pie selected_monitor / noheading percent=inside;
where yea2=99;
title1 "year of birth : 1999";
run;
proc gchart data=pie;
goptions horigin=5.25;
pie selected_monitor / noheading percent=inside;
where yea2=0;
title2 "year of birth: 2000";
run;
proc gchart data=pie;
pie selected_monitor / noheading percent=inside;
where yea2=1;
title3 " year of birth: 2001";
run;
proc gchart data=pie;
pie selected_monitor / noheading percent=inside;
where yea2=2;
title4 "year of birth: 2002";
run; | a********s 发帖数: 188 | 2 There are few different methods to put multigraphs on one page. The idea is
to generate the graphs first and then use PROC GREPLAY. Below is a simple
sample code to do this. I ever used another more flexible way to generate
graphs, but could not find the code, and also forgot how to do so ...
data a;
do i=1 to 100;
x = rannor(10);
y= rannor(4)+1;
z = rannor(3)+2;
w = rannor(5) + 3;
output;
end;
run;
proc gchart data =a;
pie x/name="pie1";
run;
quit;
proc gchart data =a;
pie y/name="pie2";
run;
quit;
proc gchart data =a;
pie z/name="pie3";
run;
quit;
proc gchart data =a;
pie w/name="pie4";
run;
quit;
options nodate;
goptions hsize= 12in vsize=4in;
ods pdf file="c:\test.pdf";
proc greplay igout=work.gseg tc=sashelp.templt
template=l2r2 nofs;
treplay 1:pie1 2:pie2 3:pie3 4:pie4;
run;
quit;
ods pdf close; | a********s 发帖数: 188 | 3 By the way, if it is possible and feasible, plot graphs in R would be much
more convenient. In SAS, you have to set up lots of graphical options to
make it nice. | S********a 发帖数: 359 | 4 想生成11~19个slice for each pie,一页4个pie (2x2), 我用SAS做完了,但是图不
好看,因为slice 太多了,label和percent are on top of each other. 用R的话可以
改善吗?
【在 a********s 的大作中提到】 : By the way, if it is possible and feasible, plot graphs in R would be much : more convenient. In SAS, you have to set up lots of graphical options to : make it nice.
| a********s 发帖数: 188 | 5 可以试试先把那些label放到pie的外面,不要用inside的option。 | S********a 发帖数: 359 | 6 label 已经是在pie的外面了,只是有的slice实在是太细小了,但是又不想放到other
里去,结果就label重叠了。
说到R,我真心请教,弱弱的问:
有year=1999,2000,2001,2002,2003, monitor是地名,我想每年做一个pie chart of
the number of observations contributed by each monitor.
已经引进了dataset 如下:
mydata = read.csv(file="C:\pie.csv", header=TRUE, sep=",")
怎么根据每年做pie chart 呢? 谢谢!
送包子先
【在 a********s 的大作中提到】 : 可以试试先把那些label放到pie的外面,不要用inside的option。
| s*r 发帖数: 2757 | | a********s 发帖数: 188 | 8 简单直接的做就是loop一下,我不知道有没有package一次性做好的。
attach(mydata)
year.id <- unique(year)
for(i in 1:length(year.id)){
temp <- mydata[year == year.id[i], ]
y <- table(temp$monitor)
pie(y, labels = paste(names(y)))
}
detach(mydata)
other
【在 S********a 的大作中提到】 : label 已经是在pie的外面了,只是有的slice实在是太细小了,但是又不想放到other : 里去,结果就label重叠了。 : 说到R,我真心请教,弱弱的问: : 有year=1999,2000,2001,2002,2003, monitor是地名,我想每年做一个pie chart of : the number of observations contributed by each monitor. : 已经引进了dataset 如下: : mydata = read.csv(file="C:\pie.csv", header=TRUE, sep=",") : 怎么根据每年做pie chart 呢? 谢谢! : 送包子先
| d*******o 发帖数: 493 | 9 丫丫付包子最及时了,求长期包养。
library(gridBase)
library(lattice)
panel.piechart <-
function(x, y, labels = as.character(y),
edges = 200, radius = 0.8, clockwise = FALSE,
init.angle = if(clockwise) 90 else 0,
density = NULL, angle = 45,
col = superpose.polygon$col,
border = superpose.polygon$border,
lty = superpose.polygon$lty, ...)
{
stopifnot(require("gridBase"))
superpose.polygon <- trellis.par.get("superpose.polygon")
opar <- par(no.readonly = TRUE)
on.exit(par(opar))
if (panel.number() > 1) par(new = TRUE)
par(fig = gridFIG(), omi = c(0, 0, 0, 0), mai = c(0, 0, 0, 0))
pie(as.numeric(x), labels = labels, edges = edges, radius = radius,
clockwise = clockwise, init.angle = init.angle, angle = angle,
density = density, col = col, border = border, lty = lty)
}
piechart <- function(x, data = NULL, panel = "panel.piechart", ...)
{
ocall <- sys.call(sys.parent())
ocall[[1]] <- quote(piechart)
ccall <- match.call()
ccall$data <- data
ccall$panel <- panel
ccall$default.scales <- list(draw = FALSE)
ccall[[1]] <- quote(lattice::barchart)
ans <- eval.parent(ccall)
ans$call <- ocall
ans
}
par(new = TRUE)
piechart(VADeaths, groups = FALSE, xlab = "") | S********a 发帖数: 359 | 10 谢谢!我应该在哪里插脚?y 是monitor? x 是文件名?
实在是自己太弱了。。。。
【在 d*******o 的大作中提到】 : 丫丫付包子最及时了,求长期包养。 : library(gridBase) : library(lattice) : panel.piechart <- : function(x, y, labels = as.character(y), : edges = 200, radius = 0.8, clockwise = FALSE, : init.angle = if(clockwise) 90 else 0, : density = NULL, angle = 45, : col = superpose.polygon$col, : border = superpose.polygon$border,
| S********a 发帖数: 359 | 11 谢谢,pie charts已经做好了,可是问题是每个chart有19个slice,临近的label(在
圆圈以外)都重叠在一起了,有什么办法能更好看些吗?
【在 a********s 的大作中提到】 : 简单直接的做就是loop一下,我不知道有没有package一次性做好的。 : attach(mydata) : year.id <- unique(year) : for(i in 1:length(year.id)){ : temp <- mydata[year == year.id[i], ] : y <- table(temp$monitor) : pie(y, labels = paste(names(y))) : } : detach(mydata) :
| a********s 发帖数: 188 | 12 You may try this.
attach(mydata)
year.id <- unique(year)
for(i in 1:length(year.id)){
temp <- mydata[year == year.id[i], ]
y <- table(temp$monitor)
m <- length(y)
colors <- 1:m
pie(y, col= colors)
legend(1.5, 0.5, labels = paste(names(y)), fill=colors)
} | S********a 发帖数: 359 | |
|