Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is this not plotting? I keep getting the same error. #20

Closed
wpatemc opened this issue May 17, 2020 · 7 comments
Closed

Why is this not plotting? I keep getting the same error. #20

wpatemc opened this issue May 17, 2020 · 7 comments

Comments

@wpatemc
Copy link

wpatemc commented May 17, 2020

See the attached screenshot.
<img width="1415" alt="Screen Shot 2020-05-17 at 1 30 23 PM" src="https://user-images.githubusercontent.com/65510741/82159476-28070180-9843-11ea-8433-d70ccf3045c5.png"

@malcolmbarrett
Copy link

Looks like you have a + at the beginning of line 10 that shouldn't be there

@wpatemc
Copy link
Author

wpatemc commented May 18, 2020

Thanks. I tried that but it didn't work. I'm knew to R so I must have missed a step along the way.

@malcolmbarrett
Copy link

malcolmbarrett commented May 18, 2020

This code runs fine. What's different from yours? When you say you tried what I suggest, what did you try? When you're having unexpected results in R, another good approach is to restart your R session and try running again (under the Session menu in RStudio). (Note that I removed the devtools::install_github('bbc/bbplot') line because you don't need to reinstall the package every time you run the code.)

pacman::p_load('dplyr', 'tidyr', 'gapminder',
               'ggplot2',  'ggalt',
               'forcats', 'R.utils', 'png', 
               'grid', 'ggpubr', 'scales',
               'bbplot')

line_df <- gapminder %>%
  filter(country == "Malawi") 

#Make plot
line <- ggplot(line_df, aes(x = year, y = lifeExp)) +
  geom_line(colour = "#1380A1", size = 1) +
  geom_hline(yintercept = 0, size = 1, colour="#333333") +
  bbc_style() +
  labs(title="Living longer",
       subtitle = "Life expectancy in Malawi 1952-2007")

line

Created on 2020-05-18 by the reprex package (v0.3.0)

@wpatemc
Copy link
Author

wpatemc commented May 18, 2020

I got it to work when I put: plot (line <-

One more question. How do I get R to pull an image-logo from my files in the final line of code. I've tried using a web link to our website, but also .png from my harddrive. Do I need to load the image first? Possibly the image I'm using is just too big, but I didn't think that makes sense considering it's a .png vector

finalise_plot(plot_name = my_line_plot,
source = "Source: Gapminder",
save_filepath = "filename_that_my_plot_should_be_saved_to.
png",
width_pixels = 640,
height_pixels = 450,
logo_image_path = "

@wpatemc
Copy link
Author

wpatemc commented May 18, 2020

Here's the actual code that I can't get to plot:

plot (finalise_plot(plot_name = "line",
source = "Source: Gapminder",
save_filepath = "Malawi.png",
width_pixels = 640,
height_pixels = 450,
logo_image_path = "~Orionlogo.png"))

@malcolmbarrett
Copy link

Ok, let's take a step back here because you have a few things going on at once.

First, wrapping plot() around your code is not responsible for fixing your previous issue. It is also unnecessary, and I do not recommend it. What's happening underneath the hood is that plot() is explicitly printing the object. If you've got code that saves to an object (line <- #{some plot code}, it won't print by default. You need to look at line by running it either in a script or in the console pane. If you look at the code I put above, line, the plot object we created, is the last thing to run. That's why it printed the plot.

Moving on to your second question, finalise_plot() shouldn't work with plot(), as it is trying to save a file (Malawi.png), not plot something in your R session. So remove that part surrounding it.

Second, you have plot_name = "line" but it should be plot_name = line. Because line is an object that lives in your R session, you don't need to wrap it in quotation marks. I can't tell you if your company logo will work here because I don't have the file, and I don't know where it is on your computer in relation to your R session. But if it's at "~Orionlogo.png" it should now appear on the plot in the file Malawi.png.

Since this is getting a little more detailed, I'm also going to skip ahead to something I was going to bring up after we resolved your issue, which is that GitHub issues are not generally a good place to ask questions like this. You might like asking for help at a place like RStudio Community. Additionally, you can maximize your chances of getting help by sharing your code in a reproducible example. Here is a good guide on preparing R questions, as well as a list of places that are good for asking for help: https://www.tidyverse.org/help/

If these don't fix your issue, my recommendation would be to post at RStudio Community. You can feel free to tag me (my username is malcolm there) for help. The reason I am suggesting that is that GitHub issues is generally a place to file bug reports or feature requests, which this is not.

So if this doesn't solve your problem, please close this issue and ask for help there (maybe with a link to this issue).

@wpatemc
Copy link
Author

wpatemc commented May 19, 2020

Dude, you're the man. Thanks so much!

@wpatemc wpatemc closed this as completed May 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants