2

I am making a simple bar graph, and repeating an old script with some simple data, but it refuses to return a graph.

Here's dput of the data frame:

papers <- structure(list(YEAR = c(1957, 1970, 1981, 1982, 1987, 1988, 1990, 
1993, 1994, 1995, 1996, 2002, 2004, 2005, 2006, 2007, 2008, 2009, 
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018), count = c(1L, 
1L, 1L, 2L, 1L, 14L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 3L, 4L, 5L, 
3L, 5L, 4L, 6L, 5L, 13L, 4L, 5L, 6L, 12L, 2L)), row.names = c(NA, 
-27L), class = "data.frame")

And here's the ggplot script:

ggplot(papers, aes(x=YEAR,y=count)) + 
scale_y_continuous(limit=c(0,20),expand=c(0, 0)) +
scale_x_continuous(breaks=c(1955,1965,1975,1985,1995,2005,2015),
                   labels=c(1955,1965,1975,1985,1995,2005,2015)) +
geom_bar(stat="identity") +
theme(axis.text=element_text(size=10)) +
theme(panel.border = element_rect(colour = "grey50")) +
annotate("text",x=1948,y=18.5,label="ALL AREAS",
         family="arial",size=5.5,hjust=0,color="black")

enter image description here

Why doesn't it work?

1 Answer 1

6

From ?theme

panel.border : border around plotting area, drawn on top of plot so that it covers tick marks and grid lines. This should be used with fill=NA (element_rect; inherits from rect)

So your code works fine and all that must be changed is

theme(panel.border = element_rect(colour = "grey50", fill = NA))

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.