0

Here is my code

ggplot(mtcars, aes(mpg, hp)) + 
  geom_point() + theme_clean() 

I want to remove the y-axis black line. This is my desired results enter image description here

Best,

Gregor Thomas
  • 119,032
  • 17
  • 152
  • 277
RL_Pug
  • 789
  • 3
  • 14
  • 1
    Does this answer your question? [can I separately control the x and y axes using ggplot?](https://stackoverflow.com/questions/6541329/can-i-separately-control-the-x-and-y-axes-using-ggplot) – Bappa Das Apr 14 '20 at 14:56
  • Which black line are you talking about? – Jack Brookes Apr 14 '20 at 15:02

2 Answers2

1

Try this (using theme_classic, which is kind of close to your desired result, but has both x and y axis lines present):

ggplot(mtcars, aes(mpg, hp)) + 
    geom_point() + theme_classic() +
    theme(axis.line.y = element_blank(), axis.line.x = element_line())

enter image description here

If you type theme_classic (no parenthesese), you can see all the theme elements that are used to create that theme. Note that the classic theme has axis.line applied, which creates both x and y axis lines. If you try only specifying axix.line.y = element_blank(), it does not work, since theme_classic() applies axis.line back over that command - resulting in both lines again. This is why you have to specify both here.

chemdork123
  • 10,461
  • 1
  • 14
  • 29
0

Use the folowing code

library(ggthemes)

ggplot(mtcars, aes(mpg, hp)) + 
  geom_point() + theme_hc() + 
  theme(axis.line.y = element_blank(), axis.line.x = element_line())

enter image description here

If you want to have an answer according to your code then

ggplot(mtcars, aes(mpg, hp)) +
  geom_point() +
  theme_clean()+
  theme(axis.line.y = element_blank(), axis.line.x = element_line(), plot.background=element_blank())

enter image description here

Bappa Das
  • 5,817
  • 3
  • 18
  • 40