Resolved: by using R I got stretched PNG
How to fix this right side of PNG?
Hi Muhamed,
thanks for reaching out! Did you create this image with R or with Python? I see that you've rotated the x and y-axis which might be why it's cut on one side, so if you switch them you should be ok. If this doesn't fix the issue, could you send me a screenshot of your code, so that I can troubleshoot the problem more closely?
Best,
365 Eli
it's R and I got a new problem
Hi Mohamed,
thanks for sharing your code! The error you're receiving suggests that the bar object has not been created. So you must ensure that you run line 7 and then line 14. Line 7 is where we create the bar chart object and line 14 is where you display it.
Additionally, I found two typos in your code.
Line 7: in the aesthetics layer you must change the Car.Listings to Cars.Listings variable, as this is the proper name of the data variable.
Line 12: here labels must be changed to label, as this is the proper name of the attribute.
The following code runs for me and creates the bar chart correctly:
library(ggplot2)
HW1_1_Car_Listings <- read.csv("C:/Users/nikol/Documents/ElitsaK/Rstudio/bar_chart_data.csv",
header = TRUE,
sep = ",")
bar <- ggplot(HW1_1_Car_Listings, aes(x = Brand, y = Cars.Listings)) +
geom_bar(stat = "identity", width = 0.5, color = "darkblue", fill = "navy") +
ggtitle("Car Listings by Brand") +
theme_classic() +
labs(x = NULL, y = "Number of Listings") +
geom_text(aes(label = Cars.Listings), hjust = -0.2) +
coord_flip()
bar
In addition, I was able to create a png with the Export panel in R studio and it created an image without any cropping. Let me know if that works for you!
Best,
365 Eli
Hi Eli,
thanks for replying.
I have the same proplem of th image size I think it's not a code issue, maybe it's about RStudio settings.
Hi Eli,
it's another chart and its the same so it's not a coding problem
library(ggplot2)
df_ice_cream <- read.csv("bar_chart_homework_data.csv",
header = TRUE,
sep = ",")
horizontal_bar <- ggplot(df_ice_cream,
aes(x = Cities,
y = Frequency)) +
geom_bar(stat = "identity",
width = 0.8,
color = "darkblue",
fill = "navy") +
ggtitle("Sales") +
theme_classic() +
labs(x = NULL, y = "Frequency") +
geom_text(aes(label = Frequency),
hjust = -0.2,
) +
coord_flip()
horizontal_bar
Hi Muhamed,
I was able to reproduce the issue in Rstudio. It appears, that working on a smaller screen, i.e.
a laptop, the plots are indeed cropped and unfortunately it's the same with the saved image.
If you have a seperate monitor, which is larger, the plots appeared normal,
that's why I couldn't reproduce the issue on the first go.
So the first option would be to use Rstudio with a larger screen.
The second option is to modify the image size before exporting it, like so:
You can increase the width of the image and it wouldn't be cropped, just make sure you've
checked the Maintain aspect ratio box, otherwise your image might be distorted.
Hope this helps!
Best,
365 Eli