I'm trying to get the a plot for demonstrative purpose (I know it my not make statistical sense, but it's precisely to discuss that). The plot must have factors in the X axis (Data$Site) and a certain value in the Y axis(Data$Count). For each "Site" a point must be appear with a size equal to the Data$Mean. My current code and it's results are as follows:
我试图得到一个用于示范目的的情节(我知道这不是统计意义,但正是要讨论它)。该图必须包含X轴(Data $ Site)中的因子和Y轴中的某个值(Data $ Count)。对于每个“站点”,必须出现一个大小等于Data $ Mean的点。我目前的代码及其结果如下:
> is.factor(Data$Site)
TRUE
> Data$Site
[1] Creek Shade Valley
Levels: Creek Shade Valley
> Data$Count
[1] 2.1 3.0 8.5
> Data$Mean
[1] 1.456 2.3445 1.345
plot(Data$Site, Data$Count, type = "p", pch=15, cex=Data$Mean)
Obviously, I don't want lines. I want points that are of the size of Data$Mean. Is there quick and neat a way to do it in R? I have reviewed other packages like lattice and ggplot to not avail.
显然,我不想要线条。我想要大小为Data $ Mean的点数。在R中有快速而简洁的方法吗?我已经审查过像格子和ggplot这样的其他软件包无济于事。
3 个解决方案
#1
2
Use the default method - plot.default() while turning the axes off. Then use the axis() function to create custom axes. I used a 1/20 scale for my means before using them to set cex. You may not need to do this for your data.
在关闭轴的同时使用默认方法 - plot.default()。然后使用axis()函数创建自定义轴。在使用它们来设置cex之前,我使用了1/20比例。您可能不需要为数据执行此操作。
d<-data.frame(Site=c('A','B','C'),
Mean=c(15,25,60),
Count=c(100,200,400))
> is.factor(d$Site)
[1] TRUE
plot.default(d$Site,d$Count,type='p',axes = FALSE,cex=d$Mean/20)
axis(side = 1, at = as.numeric(d$Site), labels = d$Site)
axis(side=2, at=d$Count, labels = d$count)
#2
1
You can try symbols
instead of plot
, also from the basic graphics
package:
您可以尝试使用符号而不是绘图,也可以使用基本图形包:
Data <- data.frame(Site = c("Creek", "Shade", "Valley"), Count = c(2.1, 3.0, 8.5), Mean = c(1.456, 2.3445, 1.345))
symbols(Data$Site, Data$Count, circles = Data$Mean, inches = 0.5)
You can change the symbols into other types such as squares
and stars
. Argument inches
is set to reduce the overal sizes from the default value of (1
or TRUE
). as Please refer to ?symbols
for more information
您可以将符号更改为其他类型,例如正方形和星形。参数英寸设置为从默认值(1或TRUE)减少总尺寸。有关更多信息,请参阅?符号
#3
#1
2
Use the default method - plot.default() while turning the axes off. Then use the axis() function to create custom axes. I used a 1/20 scale for my means before using them to set cex. You may not need to do this for your data.
在关闭轴的同时使用默认方法 - plot.default()。然后使用axis()函数创建自定义轴。在使用它们来设置cex之前,我使用了1/20比例。您可能不需要为数据执行此操作。
d<-data.frame(Site=c('A','B','C'),
Mean=c(15,25,60),
Count=c(100,200,400))
> is.factor(d$Site)
[1] TRUE
plot.default(d$Site,d$Count,type='p',axes = FALSE,cex=d$Mean/20)
axis(side = 1, at = as.numeric(d$Site), labels = d$Site)
axis(side=2, at=d$Count, labels = d$count)
#2
1
You can try symbols
instead of plot
, also from the basic graphics
package:
您可以尝试使用符号而不是绘图,也可以使用基本图形包:
Data <- data.frame(Site = c("Creek", "Shade", "Valley"), Count = c(2.1, 3.0, 8.5), Mean = c(1.456, 2.3445, 1.345))
symbols(Data$Site, Data$Count, circles = Data$Mean, inches = 0.5)
You can change the symbols into other types such as squares
and stars
. Argument inches
is set to reduce the overal sizes from the default value of (1
or TRUE
). as Please refer to ?symbols
for more information
您可以将符号更改为其他类型,例如正方形和星形。参数英寸设置为从默认值(1或TRUE)减少总尺寸。有关更多信息,请参阅?符号