x=~wt,
y=~mpg
)
library(plotly)
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg
)
p
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers"
)
p
str(mtcars)
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg
)
p
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers"
)
p
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
color = I("black")
)
p
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
color = I("green")
)
p
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
color = I("black")
)
p
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
marker = list(color="green", size=5)
)
p
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
marker = list(color="green", size=10)
)
p
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
marker = list(size = 7,
color = 'rgba(255, 182, 193, .9)',
line = list(color = 'rgba(152, 0, 0, .8)',
width = 3))
)
p
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
color = I("black")
)
p
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
marker = list(color="green", size=10)
)
p
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
marker = list(size = 7,
color = 'rgba(255, 182, 193, .9)',
line = list(color = 'rgba(152, 0, 0, .8)',
width = 3))
)
p
str(mtcars)
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
color = ~as.factor(cyl))
p
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
color = ~as.factor(cyl),
colors = "Set1")
p
pal <- c("red", "blue", "green")
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
color = ~as.factor(cyl),
colors = pal)
p
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
symbol = ~as.factor(cyl),
symbols =  c('circle','x','o'),
marker = list(size = 5)
)
p
str(mtcars)
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
color = ~as.factor(cyl))
p
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
color = ~as.factor(cyl),
colors = "Set1")
p
pal <- c("red", "blue", "green")
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
color = ~as.factor(cyl),
colors = pal)
p
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
symbol = ~as.factor(cyl),
symbols =  c('circle','x','o'),
marker = list(size = 5)
)
p
p= plot_ly(data=mtcars,
x=~wt,
y=~mpg,
mode="markers",
color = ~disp)
p
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type="scatter",
mode="markers",
color = ~as.factor(cyl),
size = ~hp)
p
p = layout(p, showlegend = FALSE)
p
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type="scatter",
mode="markers",
color = ~as.factor(cyl),
size = ~hp)
p
p <- plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
symbol = ~as.factor(cyl),
symbols =  c('circle','x','o'),
marker = list(size = 5)) %>%
layout(showlegend = FALSE)
p
p = plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type="scatter",
mode="markers",
color = ~as.factor(cyl),
size = ~hp)
p
p <- plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
symbol = ~as.factor(cyl),
symbols =  c('circle','x','o'),
marker = list(size = 5)) %>%
layout(showlegend = FALSE)
p
p <- plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
symbol = ~as.factor(cyl),
symbols =  c('circle','x','o'),
marker = list(size = 5)) %>%
layout(legend = list(orientation = 'h'))
p
p <- plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
symbol = ~as.factor(cyl),
symbols =  c('circle','x','o'),
marker = list(size = 5)) %>%
layout(legend = list(x = 0.8, y = 0.9))
p
p <- plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
symbol = ~as.factor(cyl),
symbols =  c('circle','x','o'),
marker = list(size = 5)) %>%
layout(legend = list(x = 1, y = 0.5))
p
p <- plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
symbol = ~as.factor(cyl),
symbols =  c('circle','x','o'),
marker = list(size = 5)) %>%
layout(title="Scatter plot using R Plotly",
xaxis=list(title="Weight"),
yaxis=list(title="MPG"))
p
p <- plot_ly(data=mtcars,
x=~wt,
y=~mpg,
type = "scatter",
mode = "markers",
symbol = ~as.factor(cyl),
symbols =  c('circle','x','o'),
marker = list(size = 5)) %>%
layout(title="Scatter plot using R Plotly",
xaxis=list(title="Weight", showgrid=FALSE),
yaxis=list(title="MPG", showgrid=FALSE))
p
# score.sentiment function is self written (getting positive score)
# gov_sentiment= score.sentiment_p(editorials, pos)
gov_not.blank<-subset(gov_sentiment, score!=0)
gov_articles<-gov_not.blank
gov_senti_score <-sum(gov_articles$score)
gov_articles<-gov_articles$text
#score.sentiment function is self written (getting negative score)
opp_sentiment= score.sentiment_n(editorials, neg)
opp_not.blank<-subset(opp_sentiment, score!=0)
opp_articles<-opp_not.blank
opp_senti_score <-sum(opp_articles$score)
opp_senti_score
opp_articles<-opp_articles$text
clean.text <- function(x, lowercase=TRUE, numbers=TRUE, punctuation=TRUE, spaces=TRUE)
{
# x: character string
# lower case
if (lowercase)
x = tolower(x)
# remove numbers
if (numbers)
x = gsub("[[:digit:]]", "", x)
# remove punctuation symbols
if (punctuation)
x = gsub("[[:punct:]]", "", x)
# remove extra white spaces
if (spaces) {
x = gsub("[ \t]{2,}", " ", x)
x = gsub("^\\s+|\\s+$", "", x)
}
# return
x
}
# Remove stop words from text
gov_articles<-clean.text(gov_articles)
opp_articles<-clean.text(opp_articles)
gov_articles<-removeWords(gov_articles,new_stop_wor
# Parameters
# sentences: vector of text to score
# pos.words: vector of words of postive sentiment
#progress: passed to laply() to control of progress bar
#create simple array of scores w1th laply
scores = laply(sentences,
function(sentence, pos.words)
{
#remove punctuation using global substitute
sentence = gsub("[[ :punct:]]", "" ,sentence)
# remove control characters
sentence = gsub("[[ :cntrl:]]", "" ,sentence)
#remove digits
sentence = gsub('\\d+' , '', sentence)
#define error handling function when  trying tolower
tryTolower = function(x)
{
#create miissing value
y = NA
#trycatch error
try_error = tryCatch(tolower (x) , error= function(e) e)
# if not an error
if (!inherits(try_error, "error"))
y = tolower (x)
# result
return(y)
}
#use tryTolower with sapply
sentence = sapply(sentence, tryTolower)
# split sentence into ngrams with BigramTokenizer (RWeka package)
ngram.list = BigramTokenizer(sentence)
words = unlist(ngram.list)
#sum up all positive terms
pos.matches = match(words, pos.words)
#get the position of the matched term or NA
#just want a TRUE /FALSE
pos.matches = !is.na(pos.matches)
#final score
score = sum(pos.matches)
return(score)
} , pos.words,  .progress=.progress)
#data frame with scores for each sentence
scores.df = data.frame(text=sentences, score=scores)
return(scores.df)
}
#function
score.sentiment_n = function(sentences, neg.words, .progress='none')
{
# Parameters
# sentences: vector of text to score
# neg.words: vector of worrds of negative sentiment
#progress: passed to laply() to control of progress bar
#create simple array of scores w1th laply
scores = laply(sentences,
function(sentence, neg.words)
{
#remove punctuation using global substitute
sentence = gsub("[[ :punct:]]", "" ,sentence)
# remove control characters
sentence = gsub("[[ :cntrl:]]", "" ,sentence)
#remove digits
sentence = gsub('\\d+' , '', sentence)
#define error handling function when  trying tolower
tryTolower = function(x)
{
#create miissing value
y = NA
#trycatch error
try_error = tryCatch(tolower (x) , error= function(e) e)
# if not an error
if (!inherits(try_error, "error"))
y = tolower (x)
# result
return(y)
}
#use tryTolower with sapply
sentence = sapply(sentence, tryTolower)
# split sentence into ngrams with BigramTokenizer (RWeka package)
ngram.list = BigramTokenizer(sentence)
words = unlist(ngram.list)
#sum up all negative terms
neg.matches = match(words, neg.words)
#get the position of the matched term or NA
#just want a TRUE /FALSE
neg.matches = !is.na(neg.matches)
#final score
score = sum(neg.matches)
return(score)
} , neg.words,  .progress=.progress)
#data frame with scores for each sentence
scores.df = data.frame(text=sentences, score=scores)
return(scores.df)
}
# score.sentiment function is self written (getting positive score)
# gov_sentiment= score.sentiment_p(editorials, pos)
gov_not.blank<-subset(gov_sentiment, score!=0)
gov_articles<-gov_not.blank
gov_senti_score <-sum(gov_articles$score)
gov_articles<-gov_articles$text
#score.sentiment function is self written (getting negative score)
opp_sentiment= score.sentiment_n(editorials, neg)
opp_not.blank<-subset(opp_sentiment, score!=0)
opp_articles<-opp_not.blank
opp_senti_score <-sum(opp_articles$score)
opp_senti_score
opp_articles<-opp_articles$text
clean.text <- function(x, lowercase=TRUE, numbers=TRUE, punctuation=TRUE, spaces=TRUE)
{
# x: character string
# lower case
if (lowercase)
x = tolower(x)
# remove numbers
if (numbers)
x = gsub("[[:digit:]]", "", x)
# remove punctuation symbols
#uplaoding file
pos <- readLines("PML.txt")
# All lowercase
pos<-tolower(pos)
#uplaoding file
neg <- readLines("OPPS.txt")
# All lowercase
neg<-tolower(neg)
#uplaoding file
editorials <- readLines("news.csv")
#uplaoding file
custom_stop_words <- readLines("customStopWords.txt")
new_stop_words<- c(custom_stop_words, stopwords("en"))
#-----------------------------------------------------------------------------
#Function to create n-gram
BigramTokenizer <- function(x) NGramTokenizer(x, Weka_control(min=2,max=4))
#function
score.sentiment_p = function(sentences, pos.words, .progress='none')
{
# Parameters
# sentences: vector of text to score
# pos.words: vector of words of postive sentiment
#progress: passed to laply() to control of progress bar
#create simple array of scores w1th laply
scores = laply(sentences,
function(sentence, pos.words)
{
#remove punctuation using global substitute
sentence = gsub("[[ :punct:]]", "" ,sentence)
# remove control characters
sentence = gsub("[[ :cntrl:]]", "" ,sentence)
#remove digits
sentence = gsub('\\d+' , '', sentence)
#define error handling function when  trying tolower
tryTolower = function(x)
{
#create miissing value
y = NA
#trycatch error
try_error = tryCatch(tolower (x) , error= function(e) e)
# if not an error
if (!inherits(try_error, "error"))
y
shiny::runApp('Desktop/shinylayouts/gridlayout demo')
runApp('Desktop/shinylayouts/navbarpage demo')
runApp('Desktop/shinylayouts/navbarpage demo')
runApp('Desktop/shinylayouts/navbarpage demo')
runApp('Desktop/shinylayouts/navbarpage demo')
runApp('Desktop/shinylayouts/navbarpage demo')
runApp('Desktop/shinylayouts/navbarpage demo')
runApp('Desktop/shinylayouts/navbarpage demo')
runApp('Desktop/shinylayouts/navbarpage demo')
runApp('Desktop/shinylayouts/navbarpage demo')
runApp('Desktop/shinylayouts/navbarpage demo')
runApp('Desktop/shinylayouts/navbarpage demo')
runApp('Desktop/shinylayouts/navbarpage demo')
runApp('Desktop/shinylayouts/navbarpage demo')
runApp('Desktop/shinylayouts/navbarpage demo')
runApp('Desktop/shinylayouts/navbarpage demo')
runApp('Desktop/shinylayouts/navbarpage demo')
runApp('Desktop/shinylayouts/navbarpage demo')
setwd("~/Desktop/R-Shinyapp-Tutorial/shinylayouts/navlistpanel demo")
list.files()
file.edit(c("server.R", "ui.R"))
shiny::runApp()
runApp()
runApp()
runApp()
runApp()
setwd("~/Desktop/R-Shinyapp-Tutorial/shinylayouts/shinythemes demo")
list.files()
file.edit(c("server.R", "ui.R"))
runApp()
runApp()
runApp()
runApp()
