Geom 审美仅针对某个级别或类别
Geom aesthetic only for some level or category
我正在尝试控制某些类别或级别的几何美学,例如
library(ggplot2)
library(ggrepel)
library(treemapify)
set.seed(123)
Cases = round(rnorm(16, 500, 22))
Country = LETTERS[seq( from = 1, to = 16 )]
df = data.frame(Cases,Country)
df=rbind(df, data.frame(Country='Total', Cases = round(sum(df$Cases))))
ggplot(df, aes(area =Cases , fill = Country, label = Cases)) +
geom_treemap() +
geom_treemap_text(fontface = "bold.italic", colour = "white", place = "centre", grow = T, min.size = 1)
这产生了这个情节:
我的目标是得到一个这样的图表,其中 Total size 与其他国家/地区相似,因此我删除了 Total 行,只是为了显示每个国家/地区不同数字的大小。
df=df[!grepl('Total',df$Country),]
ggplot(df, aes(area =Cases , fill = Country, label = Cases)) +
geom_treemap() +
geom_treemap_text(fontface = "bold.italic", colour = "white", place = "centre", grow = T, min.size = 1)
我的目标是获得像其他国家一样的总规模。为此,我尝试使用过滤器控制 grow = F,这是我的示例:
ggplot(df, aes(area =Cases , fill = Country, label = Cases)) +
geom_treemap() +
{if(df$Country=="Total") geom_treemap_text(fontface = "bold.italic", colour = "white", place = "centre", grow = F, min.size = 1)} +
{if(df$Country!="Total") geom_treemap_text(fontface = "bold.italic", colour = "white", place = "centre", grow = T, min.size = 1)}
要保持大小不变,您可以给 area
一个静态值,而不是使用 cases
。
library(ggplot2)
library(ggrepel)
library(treemapify)
ggplot(df, aes(area = 10 , fill = Country, label = Cases)) +
geom_treemap() +
geom_treemap_text(fontface = "bold.italic", colour = "white",
place = "centre", grow = T, min.size = 1)
我正在尝试控制某些类别或级别的几何美学,例如
library(ggplot2)
library(ggrepel)
library(treemapify)
set.seed(123)
Cases = round(rnorm(16, 500, 22))
Country = LETTERS[seq( from = 1, to = 16 )]
df = data.frame(Cases,Country)
df=rbind(df, data.frame(Country='Total', Cases = round(sum(df$Cases))))
ggplot(df, aes(area =Cases , fill = Country, label = Cases)) +
geom_treemap() +
geom_treemap_text(fontface = "bold.italic", colour = "white", place = "centre", grow = T, min.size = 1)
这产生了这个情节:
我的目标是得到一个这样的图表,其中 Total size 与其他国家/地区相似,因此我删除了 Total 行,只是为了显示每个国家/地区不同数字的大小。
df=df[!grepl('Total',df$Country),]
ggplot(df, aes(area =Cases , fill = Country, label = Cases)) +
geom_treemap() +
geom_treemap_text(fontface = "bold.italic", colour = "white", place = "centre", grow = T, min.size = 1)
我的目标是获得像其他国家一样的总规模。为此,我尝试使用过滤器控制 grow = F,这是我的示例:
ggplot(df, aes(area =Cases , fill = Country, label = Cases)) +
geom_treemap() +
{if(df$Country=="Total") geom_treemap_text(fontface = "bold.italic", colour = "white", place = "centre", grow = F, min.size = 1)} +
{if(df$Country!="Total") geom_treemap_text(fontface = "bold.italic", colour = "white", place = "centre", grow = T, min.size = 1)}
要保持大小不变,您可以给 area
一个静态值,而不是使用 cases
。
library(ggplot2)
library(ggrepel)
library(treemapify)
ggplot(df, aes(area = 10 , fill = Country, label = Cases)) +
geom_treemap() +
geom_treemap_text(fontface = "bold.italic", colour = "white",
place = "centre", grow = T, min.size = 1)