2
我繪製barplot在R.我在Barplot酒吧之間的線新河如何繪製文本和,使用R
我需要實現從如下代碼的PDF文件
輸出https://drive.google.com/file/d/0B3XlF206d5UrUFcwbTY5eU9mbDA/view?usp=sharing
從,如果你看到PDF文件,也有連接條線和text.I現在無法實現R.同任何人都可以幫助我。
以下是我的代碼。
# Reading from the csv file
hotdogs <-read.csv("hot-dogcontest-winners.csv",sep=",", header=TRUE)
# Colouring the bar based on conditions.
fill_colors <- c()
for (i in 1:length(hotdogs$New.record)){
if (hotdogs$New.record[i] == "1") {
fill_colors <- c(fill_colors, "#31D331")
}
else
{
fill_colors <- c(fill_colors, "#D5D8D4")
}
}
# Output to a pdf file.
pdf("my_plot.pdf", width=25, height=10)
# Plotting the bar graph.
barplot(hotdogs$Dogs.eaten, names.arg=hotdogs$Year, col=fill_colors,space=0.5,xlab="Year",border=NA,ylab="Hot dogs and buns (HDB) eaten"
,main="Nathan's Hot Dog Eating Contest Results from 1980-2017")
axis(1, at = seq(1980,2016, by = 2),col="black",tcl=0)
# Making the yaxis not visible.
axis(2, col = "white", tcl = 0)
# Creating texts and placing it in certain co-ordinates.
text(10,65,"Nathan's hot dog eating contest every July 4th has been going on since the early 1900s,but it wasn't
until 2001,when things got serious.Takeru Kobayashi from Japan raised the bar, more than doubling
the previous world record.Highlighted bars indicate new records.")
text(30,65,"Matthew Stonnie won in 2015 , after Joey Chestnut won 8 consecutive times")
text(10,25,"Frank Dellarosa sets a new
world record with 21 and half HDBs")
text(20,55,"In 2001,Takeru Kobayashi, gets his first
win in the competition.He went on to win five
more years in a row.")
到目前爲止能夠實現這一點。
https://drive.google.com/file/d/0B3XlF206d5UrcThwekxxc09MeFk/view?usp=sharing
CSV數據是存在於該位置
https://drive.google.com/file/d/0B3XlF206d5UrdXFranV6YlNKYUE/view
任何幫助理解。
我們無法運行您的代碼,因爲我們沒有數據文件。你可以發佈數據嗎?運行'dput(hotdogs)'並且將輸出粘貼到你的問題中可能是最簡單的。 – G5W
舉一個更簡單的例子。 (因爲這是基本圖形,所以可以使用'lines'功能。) –
嗨,csv文件位於以下位置 https://drive.google.com/file/d/0B3XlF206d5UrdXFranV6YlNKYUE/view?usp=分享 –