[英]How to interpret bubble plot scale and plotting negative numbers with scale_area
I asked a question about making bubble charts in ggplot2 here . 我在这里问了一个关于在ggplot2中制作气泡图的问题。
My follow-up questions are: 我的后续问题是:
1)how do I interprete the scale_size in the legend? 1)如何解释图例中的scale_size?
2) Does small dot (labeled 10) mean the data can be anything from 5-10? 2)小点(标记为10)是否表示数据可以是5-10? If the data for a particular point is 8, does scale_area function change the data point to 10 before it is presented as a dot size 10 on the graph.
如果特定点的数据为8,则scale_area函数是否会将数据点更改为10,然后才会在图表上显示为点大小10。
3) is there a way to plot negative number on ggplot bubble chart? 3)有没有办法在ggplot气泡图上绘制负数? Some software can make the negative data a color bubble.
某些软件可以使负数据成为彩色气泡。
4) I tried to incorporate scale_area and scale_alpha but the legend shows 2 scales. 4)我尝试合并scale_area和scale_alpha,但图例显示了2个比例。 I just want a combined one.
我只想要一个组合的。 How do I do that?
我怎么做?
ggplot(dataset, aes(x = N, y = PctCens, size = BiasAM, alpha=BiasAM ,label = NULL)) +
geom_point(shape = 16) +
scale_area(to = c(1, 10), breaks = c(0, 10, 30, 50, 70, 100)) +
scale_x_continuous("Sample size", limits = c(0, 100)) +
scale_y_continuous("Percent censored", limits = c(0, 100)) +
facet_wrap(~Method,ncol=2) +
theme_bw()+
opts(
panel.grid.minor = theme_blank(),
panel.background = theme_blank(),
axis.ticks = theme_blank(),
axis.title.x=theme_text(face='bold',vjust=0.2, size =12),
axis.title.y=theme_text(face='bold',angle=90, vjust=0.2,size =12))
Here is how I ended up solving my problem with negative numbers in bubble chart. 以下是我最终用气泡图中的负数解决问题的方法。
The original BiasAM (called OrgBiasAM) variable has negative numbers so I took the absolute value of it and created a new variable called BiasAM which i used in the above code. 原始的BiasAM(称为OrgBiasAM)变量具有负数,因此我获取了它的绝对值并创建了一个名为BiasAM的新变量,我在上面的代码中使用了该变量。 To distinguish between the negative and positive numbers, I made a new categorical variable called BiasAMCat using ifelse statement
为了区分负数和正数,我使用ifelse语句创建了一个名为BiasAMCat的新分类变量
dataset$BiasAMCat <-ifelse(dataset$OrgBiasMA < 0, 'Negative', 'Positive') dataset $ BiasAMCat <-ifelse(dataset $ OrgBiasMA <0,'Negative','Positive')
The modified code is now: 修改后的代码现在是:
ggplot(dataset, aes(x = N, y = PctCens, size = BiasAM, colour=factor(BiasAMCat) ,label = NULL)) +
geom_point(shape = 16) +
scale_area(to = c(1, 10), breaks = c(0, 10, 30, 50, 70, 100)) +
scale_colour_manual(name=NULL, values=c('grey','black')) + # for bw printing
scale_x_continuous("Sample size", limits = c(0, 100)) +
scale_y_continuous("Percent censored", limits = c(0, 100)) +
facet_wrap(~Method,ncol=2) +
theme_bw()+
opts(
panel.grid.minor = theme_blank(),
panel.background = theme_blank(),
axis.ticks = theme_blank(),
axis.title.x=theme_text(face='bold',vjust=0.2, size =12),
axis.title.y=theme_text(face='bold',angle=90, vjust=0.2,size =12))
Note: If you like gradient color, you can use color_gradient as suggested by Andy W instead of scale_colour_manual. 注意:如果您喜欢渐变色,可以使用Andy W建议的color_gradient而不是scale_colour_manual。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.