Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/84.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
在RStudio中绘制图形_R_Ggplot2 - Fatal编程技术网

在RStudio中绘制图形

在RStudio中绘制图形,r,ggplot2,R,Ggplot2,我一直在尝试绘制一个如图1所示的图(见下图),但我想知道如何才能在左侧显示标签 下面是我的R代码和结果: library(ggplot2) library(data.table) setwd("/users/ryan/desktop/R_Programming") moviecounts <- fread('movie-counts.csv', header = T, stringsAsFactors = F) ggplot(moviecounts[year_r

我一直在尝试绘制一个如图1所示的图(见下图),但我想知道如何才能在左侧显示标签

下面是我的R代码和结果:

library(ggplot2)
library(data.table)

setwd("/users/ryan/desktop/R_Programming")
moviecounts  <- fread('movie-counts.csv', header = T, stringsAsFactors = F)

ggplot(moviecounts[year_rank <=100]) + 
  xlim(2016,1927)+
  scale_fill_manual(values = c("#ffffff", "#afd0df", "#f6a100"))+
  geom_col(aes(fill=result, y=annual_share, x=oscars_year,group = count),    
  colour="#eeeeee")+
  coord_flip()+
  theme_minimal()
库(ggplot2)
库(数据表)
setwd(“/users/ryan/desktop/R_Programming”)

moviecounts如果您通过共享数据样本使您的问题具有可复制性,您会更容易获得帮助吗?看见只需在控制台中键入
dput(数据集的名称)
,然后将以
结构(..
开始的输出复制并粘贴到您的帖子中。如果您的数据集有很多观察结果,您可以对前二十行数据执行
dput(head(数据集的名称),20))
。此外,还有一个选项是按年进行切面(加上一些额外的样式),这将允许您将变量映射到(胶片?)x上的标签。
geom_文本
带有一些换行符和适当的手动y轴会有帮助!请不要张贴dput的图片-请复制输出并粘贴在这里。@stefan感谢您的建议。@SinhNguyen谢谢您的建议,我将尝试gemo_文本
dput(head(moviecounts, 20))

structure(list(movie_name = c("Star Wars: Episode IV - A New Hope", 
"The Wizard of Oz", "The Godfather", "Star Wars: Episode V - The Empire Strikes Back", 
"Jaws", "Psycho", "Casablanca", "Raiders of the Lost Ark", "The Terminator", 
"E.T. the Extra-Terrestrial", "Ghostbusters", "2001: A Space Odyssey", 
"Gone with the Wind", "Back to the Future", "Titanic", "The Shining", 
"Star Wars: Episode VI - Return of the Jedi", "Jurassic Park", 
"The Matrix", "King Kong"), release_year = c(1977L, 1939L, 1972L, 
1980L, 1975L, 1960L, 1942L, 1981L, 1984L, 1982L, 1984L, 1968L, 
1939L, 1985L, 1997L, 1980L, 1983L, 1993L, 1999L, 1933L), oscars_year = c(1977L, 
1939L, 1972L, 1980L, 1975L, 1960L, 1943L, 1981L, 1984L, 1982L, 
1984L, 1968L, 1939L, 1985L, 1997L, 1980L, 1983L, 1993L, 1999L, 
1933L), ceremony = c("50th", "12th", "45th", "", "48th", "", 
"16th", "54th", "", "55th", "", "", "12th", "", "70th", "", "", 
"", "", ""), result = c("N", "N", "W", "", "N", "", "W", "N", 
"", "N", "", "", "W", "", "W", "", "", "", "", ""), count = c(4965L, 
3291L, 1767L, 1748L, 1570L, 1563L, 1454L, 1396L, 1355L, 1331L, 
1225L, 1176L, 1154L, 1150L, 1128L, 1127L, 1091L, 1081L, 1081L, 
1053L), overall_rank = 1:20, year_rank = c(1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L), 
    annual_share = c(0.551789286508113, 0.503441945846719, 0.33695652173913, 
    0.20161476355248, 0.313123254886318, 0.434166666666667, 0.486776029460998, 
    0.226182760855476, 0.143416596104996, 0.164829721362229, 
    0.129657070279424, 0.216017634092579, 0.176533578093927, 
    0.174374526156179, 0.171715634038666, 0.129988465974625, 
    0.164878343660269, 0.160647941744687, 0.142857142857143, 
    0.376879026485326)), row.names = c(NA, -20L), class = c("data.table", 
"data.frame"), .internal.selfref = <pointer: 0x7f9e868174e0>)