When I create a plot of my data in R studio, the values on the y axis are displayed correctly as (0, 200). However, when copying and pasting this code into an r-markdown file and knitting it into a pdf, the y axis is displayed as (0, 2.0). How can I prevent the scale from being changed when knitting the document?

I have tried using scale_y_continuous to change the limits back to (0,200) which changed the scale but not the values of the data points back to the original scale. When doing this, I just had a bunch of data points hovering around y= 0 to y = 2.0 on a plot that went up to 200. I have also tried previewing the code in the r-markdown file. It comes up normally in R studio and when previewed in R markdown, but changes when it is knit together into a pdf.

code <- c(85003, 85006, 85007, 85008, 85009, 85012, 85013, 85014, 85015, 85016)
mean <- c(4.80000, 32.50000,  4.00000, 60.00000,  
5.25000, 93.50000, 19.50000, 77.80000, 24.71429, 92.66667)
table <- cbind(code, mean)

The actually data set has 119 observations of code and mean. The code is just a categorical variable, and the range of mean for the full data set is (1.00, 198.75).

This is the code I used to create the plot (modified slightly to protect the info):

ggplot(table, aes(x=as.factor(code))) +
  geom_point(aes(y=mean)) +
  ylab("Normalized Count") +
  xlab("Code") +

I used the theme to remove the labels for the codes, as there are 119 of them and they aren't really relevant for this visualization. I just want to see if a difference exists between codes easily.

I want the points to be plotted on a y scale from (0,200) but when knitting the document the y scale is automatically changed to (0.0, 2.0).

0 Answers