ggx带你用自然语言来书写R代码

ANERYAN R语言数据分析指南 2023-06-13 23:35 发表于陕西

欢迎关注R语言数据分析指南

本节来介绍一款使用自然语言来调整R代码进行图形绘制的R包「ggx」,其主要作用是通过自然语言来调整代码此外还可以作为代码提示器使用。感觉挺有趣的,更多详细内容请参考作者官方文档。

官方文档

https://github.com/brandmaier/ggx

关注下方公众号下回更新不迷路

加载R包

install.packages("ggx")
library(ggx)
library(tidyverse)

案例1 常规绘图

ggplot(data=iris, 
       mapping=aes(x=Sepal.Length, 
                   y=Petal.Length, color=Species))+
  geom_point()
图片

案例 2 gg_语法

ggplot(data=iris, 
       mapping=aes(x=Sepal.Length, 
                   y=Petal.Length, color=Species))+
  geom_point()+
  gg_("hide legend")
图片

案例 3

ggplot(data=iris, 
       mapping=aes(x=Sepal.Length, 
                   y=Petal.Length, color=Species))+
  geom_point()+
  gg_("rotate x-axis labels by 90°")+
  gg_("set x-axis label to 'Length of Sepal'")
图片

案例 4

ggplot(data=iris, 
       mapping=aes(x=Sepal.Length, 
                   y=Petal.Length, color=Species))+
  geom_point()+
  gg_("double the font size on the x-axis label")
图片

案例 5 定义颜色

ggplot(data=iris, 
       mapping=aes(x=Sepal.Length, 
                  y=Petal.Length, color=Species))+
  geom_point()+
  gg_("add 'Hello World' as plot title")+
  gg_("paint the plot title in a beautiful orange")+
  gg_("set the color of the x-axis label to blue")
图片

可以看到ggx可以用自然语言的写法来调整代码,除此之外ggx还可以作为提示工具来提供对应的帮助代码,如下所示。

gghelp("I want to remove my plot legend")
#> theme(legend.position = "none")
gghelp("Please hide the legend")
#> theme(legend.position = "none")
gghelp("Get rid of that stupid legend")
#> theme(legend.position = "none")

有需要学习个性化数据可视化的朋友,欢迎到小编的「淘宝店铺」 「R语言数据分析指南」购买「2023年度会员文档」同步更新中 初始价格99元6月后将调整价格为「149元」,内容主要包括各种「高分论文的图表分析复现以及一些个性化图表的绘制」均包含数据+代码;按照往年数据小编年产出约在150+以上

购买后微信发小编订单截图即邀请进新的会员交流群,小编的文档为按年售卖,只包含当年度的「除系列课程外」的文档,有需要往年文档的朋友也可下单购买,需要了解更多信息的朋友欢迎交流咨询。

淘宝扫一扫

图片

2023会员群案例展示

图片图片图片图片图片图片图片图片

文档内容展示

图片图片


收录于合集 #有趣R包分享
 32
上一篇ggtricks丰富多彩绘圈图下一篇pycirclize带你轻松绘制基因组图

微信扫一扫
关注该公众号