Learn R package together--(1)

简介: ggrepel包此包可解决标签重合问题

Learn R package together--(1)


ggrepel包

此包可解决标签重合问题

# 解决样品标签重叠
library(ggrepel)
set.seed(123)
ggplot(mtcars)+ geom_point(aes(wt, mpg), color="red")+ 
  geom_text_repel(aes(wt, mpg, label=rownames(mtcars)))+
  theme_classic(base_size = 16)
#geom_label_repel()基于geom_label(),
#它将标签置于一个小方框中是基于geom_label()
ggplot(mtcars)+ geom_point(aes(wt, mpg), color="grey", size=5)+
  geom_label_repel(aes(wt, mpg, fill=factor(cyl), 
  label=rownames(mtcars)),fill = 'green')+ theme_classic(base_size = 16)

image.png

R中图片导入ppt中

此包方便不会在R中调图细节者使用

export包现在或许不好装了,推荐另一种导入方法(eoffice)

library(export)
graph2ppt(file="test.pdf", dpi=400, height = 5, aspectr=4) #导出至PPT
#另一种导入ppt包 小例子
library(eoffice)
f = "./eoffice.pptx"
p <- plot(1:10)
topptx(p, f)
o(f) #R中直接打开
这个o函数就在rvcheck这个包里,如下所示,我们可以把他写在Rprofile.site文件中的First函数里,自动启用

image.png

scale、ggsci、RColorBrewer包

查看主题颜色的十六进制

library(ggsci)
mypal = pal_igv("default", alpha =0.7)(10)##提取颜色
library("scales")
show_col(mypal)##对应颜色代码
#另一个常见的颜色主题包
library(RColorBrewer)
display.brewer.all() #查看所有色板
mi = brewer.pal(10,"Set1")
show_col(mi)

image.png

image.png

palettetown

Github地址:https://github.com/timcdlucas/palettetown

最喜欢的调色包,该包包含了380多种调色板,大大的满足了我们对色彩的需求。

library(palettetown)
#设置调色板
pokedex()
#第一个数字代表展示pokemon从2开始的10个调色板
#第二个数字是展示调色板的前多少个
pokedex(2,7) #2-11调色板的前7个
#当然,第一个数字换成调色板的id也可以
pokedex('ivysaur',2)
#若我们想看指定调色板的十六进制颜色,可以利用scales包
col = pokepal(pokemon = 1, spread = 10)
scales::show_col(col)
#显示10个相当色盲友好的调色板
pokedex(cb = 1)
#基本的绘图
plot(rnorm(20), rnorm(20), col = pokepal(pokemon = 137, spread = 6), pch = 16, cex = 1.8)
#ggplot2
library(ggplot2)
qplot(Sepal.Length, Sepal.Width, colour = Species, data=iris, size = 2) +
  scale_colour_poke(pokemon = 156, spread = 3)
qplot(factor(carb), data=mtcars, geom="bar", 
      fill = factor(carb)) +
  scale_fill_poke(pokemon = 'Quilava', spread = 6)

image.png

最后来个小pie图,看下所剩时光吧,道阻且长,还要继续努力!!

x=ggtree::Date2decimal('2020-05-21') - 2020
pie(c(x, 1-x), col=colorspace::rainbow_hcl(2),
    labels=c("已经过了\t38%了,加油吧","2020还剩下这么多\n61%"))

image.png

相关文章
|
1月前
|
Python
【Python】解决Can‘t find model ‘en‘. It doesn‘t seem to be a shortcut link, a Python package or a valid
在使用以下代码时,报错Can’t find model ‘en’. It doesn’t seem to be a shortcut link, a Python package or a valid path to a data directory.
41 1
|
1月前
|
机器学习/深度学习 Linux TensorFlow
【Tensorflow 2】解决tensorflow.python.framework.errors_impl.UnknownError: [_Derived_] Fail to find the...
本文解决了在使用TensorFlow 2.0和Keras API时,尝试使用双向LSTM (tf.keras.layers.Bidirectional) 出现的未知错误问题,并提供了三种解决该问题的方法。
27 3
|
11月前
tensorflow.python.framework.errors_impl.InvalidArgumentError
tensorflow.python.framework.errors_impl.InvalidArgumentError:logits and labels must be broadcastable: logits_size=[8,4] labels_size=[8,2]训练模型时报错,tensorflow.python.framework.errors_impl.InvalidArgu...
100 1
|
人工智能
Learn R package together--(3)
论文中作图经常会有合并图排版需求,一般会放入PPT中或AI手动调节,若是在R中出图前直接调好岂不是更美滋滋,So本次就介绍几种关于合并图形的包cowplot、gridExtra、ggpubr、patchwork
64 0
Learn R package together--(2)
介绍俩个小众但实用的包wherepackage、rPlotter
72 0
【YOLOV5-6.x讲解】常用工具类 models/common.py
【YOLOV5-6.x讲解】常用工具类 models/common.py
351 0
|
缓存 开发工具 Python
[oeasy]python0140_导入_import_from_as_namespace_
[oeasy]python0140_导入_import_from_as_namespace_
90 0
|
算法 Python
包引入报错 ImportError: cannot import name ‘best_partition‘ from ‘community‘
包引入报错 ImportError: cannot import name ‘best_partition‘ from ‘community‘
包引入报错 ImportError: cannot import name ‘best_partition‘ from ‘community‘
|
异构计算 Python
【谁说视频不能P】之基于PaddleHub的100行代码P阿力木视频
【谁说视频不能P】之基于PaddleHub的100行代码P阿力木视频
96 0
【谁说视频不能P】之基于PaddleHub的100行代码P阿力木视频
No package ‘libpeas-1.0‘ found/No package ‘libpeas-gtk-1.0‘
No package ‘libpeas-1.0‘ found/No package ‘libpeas-gtk-1.0‘
45 0