Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ggplot2-R中的条形图ot直方图-绘制多个变量_R_Ggplot2_Plot_Visualization - Fatal编程技术网

ggplot2-R中的条形图ot直方图-绘制多个变量

ggplot2-R中的条形图ot直方图-绘制多个变量,r,ggplot2,plot,visualization,R,Ggplot2,Plot,Visualization,很抱歉,我对R还是一个新手,我一直试图自己做这件事,但一直在努力 我试图对2007年到2013年间的“业余”标签做一些条形图或柱状图,以显示它是如何随时间变化的 数据集下载自:特别是查看仓鼠.csv 下面是一些数据的初始预处理 head(xhamster) # Need to change upload_date into a date column, then add new column containing year xhamster$upload_date<-as.

很抱歉,我对R还是一个新手,我一直试图自己做这件事,但一直在努力

我试图对2007年到2013年间的“业余”标签做一些条形图或柱状图,以显示它是如何随时间变化的

数据集下载自:特别是查看仓鼠.csv

下面是一些数据的初始预处理

    head(xhamster) # Need to change upload_date into a date column, then add new column containing year
    xhamster$upload_date<-as.Date(xhamster$upload_date,format="%d/%m/%Y")
    xhamster$Year<-year(ymd(xhamster$upload_date)) #Adds new column containing just the year
    xhamster$Year<-as.integer(xhamster$Year) # Changing new Year variable into an interger
    head(xhamster) # Check changes made correctly
head(xhamster)#需要将上传日期更改为日期列,然后添加包含年份的新列

xhamster$upload_date有很多方法可以解决这个问题,下面是我如何解决的:

library(tidyverse)
library(lubridate)
library(vroom)

xhamster <- vroom("xhamster.csv")
xhamster$upload_date<-as.Date(xhamster$upload_date,format="%d/%m/%Y")
xhamster$Year <- year(ymd(xhamster$upload_date))

xhamster %>% 
  filter(Year %in% 2007:2013) %>% 
  filter(grepl("Amateur", channels)) %>%
  ggplot(aes(x = Year, y = ..count..)) +
  geom_bar() +
  scale_x_continuous(breaks = c(2007:2013),
                   labels = c(2007:2013)) +
  ylab(label = "Count") +
  xlab(label = "Amateur") +
  labs(title = "Usage of 'Amateur' as a tag from 2007 to 2013",
       caption = "Data obtained from https://sexualitics.github.io/ under a CC BY-NC-SA 3.0 license") +
  theme_minimal(base_size = 14)
库(tidyverse)
图书馆(lubridate)
图书馆(vroom)
xhamster%
ggplot(不良事件(x=年份,y=计数)+
geom_bar()+
比例x连续(断裂=c(2007:2013),
标签=c(2007:2013))+
ylab(label=“Count”)+
xlab(label=“业余”)+
实验室(title=“从2007年到2013年使用“业余”作为标签”,
caption=“从中获得的数据https://sexualitics.github.io/ 根据CC BY-NC-SA 3.0许可证)+
最小主题(基本大小=14)

正如贾里德所说,有很多方法,但我想用你的方法解决它,这样你就可以更好地将解决方案内化

我刚刚改变了你在情节中的cbind:


业余爱好者您是否可以制作一个非常小的数据集(没有所有的预处理代码)来说明问题?你让它听起来就像你只是想改变标签。我真的不确定你想用你的重新编码做什么;基本上只是“频道”和“年度”,但这并没有起到多大作用。基本上,我只想将x轴上的标签更改为“2007”“2008”“2008”“2010”“2011”“2012”“2013”。我确实想尝试使用ggplot进行绘图,但老实说,在这一点上,我只希望它能够工作
    Amateur<-grep("Amateur",xhamster$channels)
    Amateur_2007<-grep("Amateur", Yr2007$channels)
    Amateur_2008<-grep("Amateur", Yr2008$channels)
    Amateur_2009<-grep("Amateur", Yr2009$channels)
    Amateur_2010<-grep("Amateur", Yr2010$channels)
    Amateur_2011<-grep("Amateur", Yr2011$channels)
    Amateur_2012<-grep("Amateur", Yr2012$channels)
    Amateur_2013<-grep("Amateur", Yr2013$channels)

    Amateur_2007 <- length(Amateur_2007)
    Amateur_2008 <- length(Amateur_2008)
    Amateur_2009 <- length(Amateur_2009)
    Amateur_2010 <- length(Amateur_2010)
    Amateur_2011 <- length(Amateur_2011)
    Amateur_2012 <- length(Amateur_2012)
    Amateur_2013 <- length(Amateur_2013)
    Amateur <- cbind(Amateur_2007, Amateur_2008, Amateur_2009,Amateur_2010, Amateur_2011, Amateur_2012, Amateur_2013)
    barplot((Amateur),beside=TRUE,col = c("red","orange"),ylim=c(0,90000))
    title(main="Usage of 'Amateur' as a tag from 2007 to 2013")
    title(xlab="Amateur")
    title(ylab="Frequency")
library(tidyverse)
library(lubridate)
library(vroom)

xhamster <- vroom("xhamster.csv")
xhamster$upload_date<-as.Date(xhamster$upload_date,format="%d/%m/%Y")
xhamster$Year <- year(ymd(xhamster$upload_date))

xhamster %>% 
  filter(Year %in% 2007:2013) %>% 
  filter(grepl("Amateur", channels)) %>%
  ggplot(aes(x = Year, y = ..count..)) +
  geom_bar() +
  scale_x_continuous(breaks = c(2007:2013),
                   labels = c(2007:2013)) +
  ylab(label = "Count") +
  xlab(label = "Amateur") +
  labs(title = "Usage of 'Amateur' as a tag from 2007 to 2013",
       caption = "Data obtained from https://sexualitics.github.io/ under a CC BY-NC-SA 3.0 license") +
  theme_minimal(base_size = 14)