Skip to content

Commit

Permalink
add theme function
Browse files Browse the repository at this point in the history
  • Loading branch information
Lang committed Oct 27, 2016
1 parent 258b9b4 commit c8e95b1
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 8 deletions.
4 changes: 3 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Generated by roxygen2: do not edit by hand
# Generated by roxygen2 (4.1.1): do not edit by hand

S3method("+",wordcloud2)
export(WCtheme)
export(letterCloud)
export(renderWordcloud2)
export(wordcloud2)
Expand Down
32 changes: 32 additions & 0 deletions R/plot-construction.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
##' Change the themes of wordcloud2
##'
##' @description
##' Function for Creating wordcloud theme
##'
##'
##' @param e1 wordcloud2 object
##' @param e2 wordcloud2 themes
##' @export
##' @method + wordcloud2
##' @examples
##' wc = wordcloud2(demoFreq)
##'
##' wc + WCtheme(1)
##' wc + WCtheme(2)
##' wc + WCtheme(3)
##' wc + WCtheme(2) + WCtheme(3)
`+.wordcloud2` = function(e1, e2){
if(e2$class == 1){
e1$x$minRotation = -pi/2
e1$x$maxRotation = -pi/2
}else if (e2$class ==2){
e1$x$minRotation = -pi/6
e1$x$maxRotation = -pi/6
e1$x$rotateRatio = 1
}else if (e2$class == 3){
e1$x$color = "random-light"
e1$x$backgroundColor = "grey"
}
return(e1)
}

37 changes: 37 additions & 0 deletions R/theme.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
##' Change the themes of wordcloud2
##'
##' @description
##' Function for Creating wordcloud theme
##'
##' @usage
##' WCtheme(class = 1)
##'
##' @param class class for theme in wordcloud2
##'
##' @export
##' @examples
##' wc = wordcloud2(demoFreq)
##'
##' wc + WCtheme(1)
##' wc + WCtheme(2)
##' wc + WCtheme(3)
##' wc + WCtheme(2) + WCtheme(3)

WCtheme = function(class = 1){
if(class == 1){
return(list(class =1,
minRotation = -pi/2,
maxRotation = -pi/2))
}else if (class ==2){
return(list(class =2,
minRotation = -pi/6,
maxRotation = -pi/6,
rotateRatio = 1))
}else if (class == 3| class=='Dark'){
return(list(class =3,
color = "random-light",
backgroundColor = "grey"))
}else{
stop("Out of themes~")
}
}
23 changes: 23 additions & 0 deletions man/WCtheme.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/theme.R
\name{WCtheme}
\alias{WCtheme}
\title{Change the themes of wordcloud2}
\usage{
WCtheme(class = 1)
}
\arguments{
\item{class}{class for theme in wordcloud2}
}
\description{
Function for Creating wordcloud theme
}
\examples{
wc = wordcloud2(demoFreq)

wc + WCtheme(1)
wc + WCtheme(2)
wc + WCtheme(3)
wc + WCtheme(2) + WCtheme(3)
}

2 changes: 1 addition & 1 deletion man/demoFreq.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2: do not edit by hand
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/data-definitions.R
\docType{data}
\name{demoFreq}
Expand Down
2 changes: 1 addition & 1 deletion man/demoFreqC.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2: do not edit by hand
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/data-definitions.R
\docType{data}
\name{demoFreqC}
Expand Down
2 changes: 1 addition & 1 deletion man/letterCloud.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2: do not edit by hand
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/letterCloud.R
\name{letterCloud}
\alias{letterCloud}
Expand Down
25 changes: 25 additions & 0 deletions man/plus-.wordcloud2.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/plot-construction.R
\name{+.wordcloud2}
\alias{+.wordcloud2}
\title{Change the themes of wordcloud2}
\usage{
\method{+}{wordcloud2}(e1, e2)
}
\arguments{
\item{e1}{wordcloud2 object}

\item{e2}{wordcloud2 themes}
}
\description{
Function for Creating wordcloud theme
}
\examples{
wc = wordcloud2(demoFreq)

wc + WCtheme(1)
wc + WCtheme(2)
wc + WCtheme(3)
wc + WCtheme(2) + WCtheme(3)
}

7 changes: 4 additions & 3 deletions man/wordcloud2-shiny.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2: do not edit by hand
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/renderWordcloud2.R
\name{wordcloud2-shiny}
\alias{renderWordcloud2}
Expand All @@ -16,7 +16,7 @@ renderWordcloud2(expr, env = parent.frame(), quoted = FALSE)
\arguments{
\item{outputId}{output variable to read from}

\item{width, height}{Must be a valid CSS unit (like \code{"100\%"},
\item{width,height}{Must be a valid CSS unit (like \code{"100\%"},
\code{"400px"}, \code{"auto"}) or a number, which will be coerced to a
string and have \code{"px"} appended.}

Expand All @@ -25,7 +25,7 @@ string and have \code{"px"} appended.}
\item{env}{The environment in which to evaluate \code{expr}.}

\item{quoted}{Is \code{expr} a quoted expression (with \code{quote()})? This
is useful if you want to save an expression in a variable.}
is useful if you want to save an expression in a variable.}
}
\description{
Function for plotting wordcloud2 in shiny
Expand All @@ -34,3 +34,4 @@ Function for plotting wordcloud2 in shiny
Use renderWordcloud2 to render an wordcloud2 object and use wordcloud2Output
output an wordcloud2 object. See more details in shiny package.
}

2 changes: 1 addition & 1 deletion man/wordcloud2.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2: do not edit by hand
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/wordcloud2.R
\name{wordcloud2}
\alias{wordcloud2}
Expand Down

0 comments on commit c8e95b1

Please sign in to comment.