简体   繁体   English

编辑gtrendsR的绘图输出

[英]Editing Plot Output from gtrendsR

library(gtrendsR)
library(ggplot2)
usr <- "xxxxxx@gmail.com"
psw <- "XXXXX"
gconnect(usr, psw) 
climate_trend <- gtrends(c("climate", "cop21", "global warming"), res="week")

plot(climate_trend, main="whatttt", xlab="x")

Using plot editing options such as main= or xlab= do not create changes in the plot output, despite not receiving errors. 尽管没有收到错误,但使用绘图编辑选项(例如main=xlab=不会在绘图输出中创建更改。 I have thought about using ggplot2 in conjunction with gtrendsR but that would require me converting the list data into an data.frame which I have had trouble with. 我曾考虑过将ggplot2gtrendsR结合使用,但这需要我将list数据转换为我遇到过麻烦的data.frame

I appreciate any input on editing the axis of the plot output using gtrendsR . 我很欣赏使用gtrendsR编辑绘图输出轴的任何输入。

The data frame you are probably interested in is just the climate_trend$trend element. 您可能感兴趣的数据框只是climate_trend$trend元素。 Here is what I did to get a ggplot2 graph: 以下是我为获取ggplot2图表所做的ggplot2

library(gtrendsR)
library(ggplot2)
library(reshape2)

usr <- "xxxx@gmail.com"   # any gmail address and pw will do here
psw <- "xxxxx"
gconnect(usr, psw) 
climate_trend <- gtrends(c("climate", "cop21", "global warming"), res="week")

# plot(climate_trend$trend, main="whatttt")

# now for ggplot 2
tdf <- climate_trend$trend
mdf <- melt(tdf,id.vars=c("start","end"))
ggplot(data=mdf,aes(x=start,y=value,color=variable)) + 
  geom_line() + geom_point() +
  labs(title="Whatttt")

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM