R geom_瓷砖绘制较长瓷砖&;不是方砖
我试图用R中的geom_tile()绘制热图,但是我的图中的tile并不像这里预期的输出格式那样是正方形:() 瓷砖是长方形而不是正方形。我试过使用cord_equal(),改变大小、宽度等,但都没有效果R geom_瓷砖绘制较长瓷砖&;不是方砖,r,ggplot2,tidyverse,R,Ggplot2,Tidyverse,我试图用R中的geom_tile()绘制热图,但是我的图中的tile并不像这里预期的输出格式那样是正方形:() 瓷砖是长方形而不是正方形。我试过使用cord_equal(),改变大小、宽度等,但都没有效果 library(tidyverse) library(office) office <- schrute::theoffice top_3_lines_per_episode <- office %>% group_by(season,episode,episode_
library(tidyverse)
library(office)
office <- schrute::theoffice
top_3_lines_per_episode <- office %>%
group_by(season,episode,episode_name,imdb_rating) %>%
count(character) %>%
top_n(3, n) %>% ungroup() %>%
mutate(episode_id = group_indices(., season,episode,episode_name,imdb_rating))
top_3_lines <- top_3_lines_per_episode %>%
mutate(episode_mod = episode_id + 3 * parse_number(season)) %>%
group_by(season) %>%
mutate(mid = mean(episode_mod)) %>%
group_by(character) %>%
add_count(name="total_lines") %>% ungroup() %>%
mutate(character=fct_lump(character,10),
character=fct_reorder(character,total_lines))
ggplot(top_3_lines, aes(x = as.factor(episode_mod), y = character, fill = imdb_rating)) +
geom_tile(color = "white", size = 0.05) +
#coord_equal(ratio = 200) +
labs(x = NULL, y = NULL, title = "The Office, Chacracters with top 3 lines") +
scale_fill_viridis(discrete = FALSE, name = "IMDB rating") +
theme(axis.text.y =element_text(size=8,face="bold"),
axis.text.x =element_blank())
库(tidyverse)
图书馆(办公室)
办公室%
计数(字符)%>%
顶部n(3,n)%%>%ungroup()%%>%
突变(插曲id=组指数(、季节、插曲、插曲名称、imdb评分))
前3行%
突变(插曲编号=插曲编号+3*解析编号(季节))%>%
按季节划分的组别%>%
突变(中期=平均值(发作期_mod))%>%
分组依据(字符)%>%
添加计数(name=“总计行”)%%>%ungroup()%%>%
变异(字符=fct_块(字符,10),
字符=fct_重新排序(字符,总行))
ggplot(最上面的3行,aes(x=as.factor(插曲修改),y=character,fill=imdb评分))+
geom_瓷砖(颜色=“白色”,尺寸=0.05)+
#坐标等于(比值=200)+
实验室(x=NULL,y=NULL,title=“办公室,前三行字符”)+
刻度填充绿色(离散=假,名称=“IMDB评级”)+
主题(axis.text.y=元素\文本(大小=8,face=“bold”),
axis.text.x=元素_blank())
由于x值太多,而且缺少很多,所以您无能为力。我想这是你能做的最好的了
ggplot(top_3_lines, aes(x = as.factor(episode_mod), y = character, fill = imdb_rating)) +
geom_tile() +
coord_equal(ratio = 10) +
labs(x = NULL, y = NULL, title = "The Office, Chacracters with top 3 lines") +
viridis::scale_fill_viridis(discrete = FALSE, name = "IMDB rating") +
theme(axis.text.y =element_text(size=8,face="bold"),
axis.text.x =element_blank())
这正是我要避免的,如果我可以为丢失的数据使用空白的白色平铺,那也是fne,但最终的视觉效果应该看起来像一个正方形。例如,请参见amplhttps://twitter.com/ellis_hughes/status/1101379476888346625/photo/1 其中一个轴的值远远大于另一个轴的值,但是瓷砖仍然是方形的。同样奇怪的是,如果我们删除top_n()并取而代之的是所有值(基本上是一种删除空白的方法),在这种情况下,我如何使它看起来是方形的。如果你能分享一个例子,我已经尝试了很多次,但都没有结果,试着把
coord_等于(比率=1)
。这将给你平方。或者翻转轴。