%unnest(v)%>%g图(aes(x=x,y=y,group=id))+geom_polygon(aes(fill=factor(yc))+coord_fixed()+theme_minimal(base_family=”Roboto Condensed") + scale_x_continuous(breaks=seq(0.5,16.5,B= 1)labels=空)+scale_y_continuous(breaks=seq(0.5,5.5,B= 1)labels=null)+scale_fill_manual(值=c(“#30bcad",““57”A337“,““F8B620”,““E034 26”,“β-EB73B3),向导=none") print_out_base Putting Words On Top of Hearts Now I have the hearts placed on grid,I want some words on top.所以我从糖果中得到灵感,我经常在情人节那天看到这些话,我不知道糖果的名字,但我觉得它叫necco甜心。## Needs at least 75 words....since there are 75 heart with some word placed on it.有些不是那些糖果,我刚编了一些。love_msgs % ## sort them alphabetically....这样更容易找到被选出来的单词。突变(idx=row_number()-1,row_group=floor(idx/15)+1)打印出_base+geom_文本(aes(x=xc,Y= YC,label=爱$msgs)颜色=#ffffffde",家庭=Roboto Condensed",size=3,FutsFoo=bold",线高=0.8,数据=%>%过滤器(theta==pi))+实验室(标题='打印并切割成碎片,然后从帽子或盒子中取出。”,x=“,“=”“,字幕=“)制作宾果游戏卡,现在我想制作5张5张宾果游戏卡,每个人都可以参与游戏。我已经生成了4张卡片作为例子。## Making Bingo Cards (Base Design) bingo_base % mutate(v=pmap(.,心脏_顶点)%>%unnest(v)%>%ggplot(aes(x=x,y=y,group=id)) + geom_polygon(aes(fill=factor(xc))) + geom_polygon(fill="“000000德”,数据=%>% filter(xc==3,yc==3))+主题\u最小值(基本\u族=“Roboto Condensed")+连续缩放(中断=C(1,2,3,4,5)标签=C(“B",“I",““N”,“G”,““),位置=顶部) + scale_y_continuous(labels=NULL) + scale_fill_manual(values=c("#30bcad",““57”A337“,““F8B620”,““E034 26”,“β-EB73B3),向导=none"+Labs(x=)“,“=”“)+coord_fixed()只是为了让卡片更有趣,让我们在每张卡片上加上一些关于爱情的引言。金宝搏网址library(rvest) love_quotes">

制作原创宾果游戏-心脏主题

January 5,二千零一十九
通过

(This article was first published on 在chi的impe[r]fect博客上,and kindly contributed to 188bet appR博主

I have learned how to draw数学方程式的心脏,in fact there are so many"曲线“你可以用方程作图。太神了,正确的?!?你可以在上面找到各种不同的曲线Wolfram Mathworld网站.我真的很好奇人们是如何找到方程本身的some of shapes??

最后家人团聚,I've played"“Bingo“,我已经很久没玩了!这是一个伟大的游戏,当你有很多年龄组,because kids were having tons of fun,但成年人和祖父母也是如此!!

所以我决定在宾果游戏上做些小改动…!不是只画1-75之间的数字,you can play bingo with words,图片,因为我真的很想用我的新heart shape drawing shape…"我决定用一些与情人节”.

用ggplot2绘制心形

You can look at past entry on how to draw大麻在这里。同样的概念。

Wolfram网站上有6个不同的心形例子,但我最喜欢第六颗心的形状。You can look at equation在这里

library(tidyverse)library(patchwork)函数在点xc和rc周围生成心形,并调整大小。Output of function is data frame with bunch of points which you can use to draw a heart!# http://mathworld.wolfram.com/HeartCurve.htmlheart_vertices <- function(xc,yc,尺寸,nPosits=100,…)面积=圆形的pi*r*r…this heart has area of 180 = r*r  radius = size*0.05  ## I'm not set on this...我只想把尺寸变小,yc=yc+0.1*半径调整心脏中心位t=seq(-pi,pi,长度out=npoints+1)x=xc+16*半径*(sin(t))^3 y=yc+半径*13*cos(t)-半径*5*cos(2*t)-半径*2*cos(3*t)-半径*cos(4*t)df<-tibble(theta=t,x=x,y=y)返回(df)以上函数,生成您需要生成心脏的点。如果你把npoints调高了,then you can draw smoother shape.heart_vertices(0,0,1)%>%ggplot()+几何线(aes(x=theta,y=x),颜色=#D22042de") +    geom_line(aes(x=theta,y=-x)颜色=#D22042de",线型=3)+这只是为了制作一条设计几何线条(aes(x=theta,y=y)颜色=“30C4C9DE”) +  geom_line(aes(x=theta,Y=-Y)颜色=“30C4C9DE”,linetype=3) + ## this is just to make a design  geom_polygon(aes(x=x,y=y)填充=“615375”,## to draw heart use x=x,Y=Y颜色=“61537520”,尺寸=10)+我只是在玩填充部分周围的线条。主题\u最小值(基本\u族=“Roboto Condensed") +  scale_x_continuous(breaks=c(-pi,-PI/2,0,pi/2,pi),标签=C(““PI”,““,“0",““,““PI”)+coord_fixed()+实验室(x=““,“=”“,字幕=pink solid line = x value & blue solid line = y value")

在网格上绘制一束心

现在我知道如何画出一颗心,我想能够在网格上绘制出一束心。由于函数heart_顶点围绕点xc和yc为单个心脏创建数据帧,我可以创建一个坐标为xc和yc的网格。

我的网格<-tibble(xc=rep(c(1:15)),时间=5)YC= ReP(C(1:5)),each=15),尺寸=0.6,id = c(1:75)) my_grid %>% ggplot(aes(x=xc,y=yc))+几何点(形状=21,尺寸=10)+几何图形文本(aes(label=id)家庭=Roboto Condensed",FutsFoo=bold")+theme_minimal()+coord_fixed())

对于网格上的每一个点,生成点以绘制心脏打印基础<-我的网格%>%突变(v=pmap(..心脏_顶点)%>%unnest(v)%>%ggplot(aes(x=x,y=y,group=id))+geom_polygon(aes(fill=factor(yc))+coord_fixed()+theme_minimal(base_family=”Roboto Condensed") +  scale_x_continuous(breaks=seq(0.5,16.5,B= 1)labels=空)+scale_y_continuous(breaks=seq(0.5,5.5,B= 1)labels=NULL) +  scale_fill_manual(values=c("#30bcad",““57”A337“,““F8B620”,““E034 26”,“β-EB73B3),向导=none"版画基础

把话放在心上

Now I have the hearts placed on grid,I want some words on top.所以我从糖果中得到灵感,我经常在情人节那天看到这些话,我不知道糖果的名字,但我觉得它叫NECCO甜心.

## Needs at least 75 words....因为有75颗心,上面有一些字。有些不是那些糖果的,我刚编了一些。爱情<-tibble(msgs=c(“143“,““1扇”,“#LOVE",“1-800\nCUPID",“HUG ME",“吻,“BE MINE",“CRAZY\n4 U",“HOLD\nHANDS",“UR\nLOVED",“PURR FECT",“求婚,“QT PIE",“配方n4爱,“冉冉升起的明星,“表NoF 2,“太甜了,“鸣叫,“TWO HEARTS",“TXT ME",““热”,“怎么了?,““命运”,“邪恶酷,“WINK\nWINK",“令人震惊的“,““XOXO”,“YOU&ME",“约姆·尼姆,“灵魂伴侣,“宝贝,“SAY YES",“HELLO",“梦想NBIG,“BFF",““高五”,“AWESOME",“微笑,“UR\nGR8",“电话\ NME”,“爱不鸟,““真实”,““真爱”,“我的宝贝,“HI GORGEOUS",““热”,“ADORE\nME",“乐趣,“LOL”,“叫我“,“PICK ME",“DEAR\nONE",“EVER\nAFTER",“情人,““全部”,“ANGEL",“RU SHY",“甜豌豆,“爱“NBUG”,“可爱的,“拥抱,““花”,“CHERISH",“巧克力”,“纸杯蛋糕,“粉碎,“秘密\n暗号“,“VALENTINE",“鸽子,“爱鸟,““钻石”,“PAARTY",“HONEY",“激情,““WWW”))这里您要确保至少有75个单词!Love_msgs<-Love_msgs%>%排列(msgs)%>%按字母顺序排序……这样更容易找到被选出来的单词。突变(idx=row_number()-1,row_group=floor(idx/15)+1)打印出_base+geom_文本(aes(x=xc,Y= YC,label=爱$msgs)颜色=#ffffffde",家庭=Roboto Condensed",size=3,FutsFoo=bold",线高=0.8,数据=%>% filter(theta==pi)) +  labs(title="打印并切割成碎片,然后从帽子或盒子中取出。”,x=“,“=”“,字幕=“)

Making Bingo Cards

Similariy现在我想制作5张5张宾果游戏卡,每个人都可以参与游戏。我已经生成了4张卡片作为例子。

制作宾果卡(基础设计)宾果基础<-tibble(xc=rep(c(1:5),时间=5)yc = rep(c(1:5),each=5),尺寸=0.6,id = c(1:25)) %>% mutate(v=pmap(.,心脏_顶点)%>%unnest(v)%>%ggplot(aes(x=x,y=y,group=id))+gem_polygon(aes(fill=factor(xc))+gem_polygon(fill=”“000000德”,数据=%>% filter(xc==3,yc==3))+  theme_minimal(base_family="Roboto Condensed")+连续缩放(中断=C(1,2,3,4,5)标签=C(“B",“I",““N”,“G”,““),位置=顶部)+连续缩放(标签=空)+手动缩放填充(值=C(“#30bcad",““57”A337“,““F8B620”,““E034 26”,“β-EB73B3),向导=none"+Labs(x=)“,“=”“) +  coord_fixed()## Just to make card little more fun,让我们在每张卡片上添加一些关于爱的引语。li金宝搏网址brary(rvest)love_quotes<-read_html(“https://lifehacks.io/inspirational-love-quotes-sayings/")%>%html节点(“H2”)%>%html_text()Love_Quotes<-Love_Quotes[2:64]35;创建函数以在每行上创建一个随机选择单词的宾果卡。使_card<-function(name=”“)Love_msgs_list<-Love_msgs%>%split(.$row_group)unique_card<-tibble(xc=rep(c(1:5),each=5),yc = rep(c(1:5),时间=5)我想从每个列表中随机选择5个。msg=love_msgs_list%>%地图(..““味精”) %>% map(.,样品,5)%>%unlist())唯一_卡<-唯一_卡%>%mutate(msg=ifelse(xc==3&yc==3,“FREE",msg))    bingo_card <- bingo_base +    geom_text(data=unique_card,AES(x= xc),Y= YC,label=msg,group=NULL),家庭=Roboto Condensed",FutsFoo=bold",颜色=white",size=3) +    labs(title=str_c(name),caption=示例(爱的语录,大小=1)宾果游戏卡使用补丁,I want to print 4 cardsmake_card("宾果卡1)BINGO CARD 2")宾果卡3)+制作卡片(“宾果卡4) + patchwork::plot_layout(ncol=2)

额外奖励:画出与心相配的花

只是觉得也可以画花。毕竟,flowers go with hearts :).You can read more 金宝搏网址about rosecurve hereor在这里

花的顶点<-函数(xc,yc,半径,k=5,npoints=300,…)t=序列(0,2*PI长度out=npoints+1)m=sqrt(半径)*cos(k*t)x=xc+m*cos(t)y=yc+m*sin(t)df<-tibble(t=t,x=x,y=y,r=m)  return(df)}flower_vertices(0,0,1,7) %>%   ggplot(aes(x=t)) +  geom_line(aes(y=x),颜色=red",线型=3)+几何线条(aes(y=y),颜色=蓝色“,线型=3)+几何多边形(aes(x=x,y=y)alpha=0.5)+主题\最小值(基\族=“Roboto Condensed") +  coord_fixed() +  labs(title="Rose Curve with K=7 - Flower with 7 Petals")

tibble(  xc=rep(c(1:5),时间=5)YC= ReP(C(1:5)),each=5),半径=0.1,k = c(1:25),id=c(1:25)) %>% mutate(v=pmap(.,花_顶点)%>%unnest(v)%>%ggplot(aes(x=x,y=y,group=id)) +  geom_polygon(aes(fill=id%%2)) +  geom_point(aes(x=xc,y=yc),数据=%>计数(ID)XCYC)size=3,形状=19,alpha=0.7) +  geom_text(aes(x=x,y=y,label=k),家庭=Roboto Condensed",尺寸=8,vjust=1,FutsFoo=bold",颜色=“000000 AE”,数据=%>% group_by(id) %>% filter(max(t)==t)) +  theme_void(base_family="Roboto Condensed")+coord_fixed()+scale_y_reverse()+scale_fill_viridis_c(begin=0.2,结束=0.7,选项=岩浆“,向导=none",alpha=0.8) +  labs(title="不同k”的玫瑰曲线,subtitle="r = cos(k * theta)")

Flower Needs Butterfly Too..

还有另一个叫做“蝶形曲线“.

I think flower deserves butterfly… So here's butterfly curve drawn in similar manner as the above.

蝶形顶点<-函数(xc,yc,nPosits=1000,…)t=序列(0,12*PIlength.out=npoints+1)  x = xc + sin(t)*(exp(cos(t))-2*cos(4*t)-sin(t/12)^5)  y = yc + cos(t)*(exp(cos(t))-2*cos(4*t)-sin(t/12)^5)  df <- tibble(x=x,y=y,t=t)%>%突变(pos=row_number())返回(df)ggplot()+geom_path(data=butterfly_顶点(1,1),aes(x=x,y=y,color=pos)) +  geom_polygon(data=butterfly_vertices(8,1),aes(x=x,y=y,填充=系数(地板(t/pi)),颜色=“000000德”)+coord_fixed()+theme_void()+scale_fill_viridis_d(alpha=0.3,向导=none") +  scale_color_viridis_c(option="岩浆“,向导=none")

留下评论作者,请关注他们博客上的链接和评论: 在chi的impe[r]fect博客上.

188bet appR-bloggers.com提供 每日电子邮件更新金宝搏网址 R新闻与 教程关于以下主题: 数据科学,, 大数据,, r作业,可视化(可视化) GGPROTT2,, 箱形图,, 地图,, animation),程序设计(程序) 演播室,, 斯威夫特,, 乳胶,, SQL,, Eclipse,, git,, hadoop,, 刮网) statistics ( 回归,, 主成分分析,, time series,, 交易) and more...



If you got this far,为什么不 subscribe for updates 从站点?选择您的口味: 电子邮件,, 推特,, 1188bet app,or facebook

注释已关闭。

搜索R-Blo188bet appggers


赞助商

千万不要错过更新!!
订阅R-Bloggers188bet app接收
最新R帖子的电子邮件。
(You will not see this message again.)

单击此处关闭(此弹出窗口将不再出现)