ggplot2 theme with no axes or grid
Here is the way to plot only the panel region:
p <- ggplot() + geom_area (data=economics, aes(x = date, y = unemploy), linetype=0) +
scale_x_date(expand = c(0,0)) + scale_y_continuous(expand = c(0,0)) +
theme(line = element_blank(),
text = element_blank(),
title = element_blank())
gt <- ggplot_gtable(ggplot_build(p))
ge <- subset(gt$layout, name == "panel")
grid.draw(gt[ge$t:ge$b, ge$l:ge$r])
Ggplot2 change the position of y axis values after removing gridlines
Do you want something like that?
ggplot(tmp, aes(factor(X2 - 1), X1, fill = X3, label = round(X3, 2))) +
geom_tile() +
geom_text() +
scale_fill_gradient(low = "springgreen", high = "darkgreen") +
coord_fixed(.5) +
theme(
panel.grid.major.x = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank(),
panel.background = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.ticks = element_blank(),
legend.position = "none"
)
The problem with y-lab spacing is due to the fact that your X2
var is continuous. So geom_tile()
positions the center of your tiles at 1, 2, 3...23, with the width of a tile == 1. The left side of the first tile starts at 1 - .5 = 0.5, that is why there is an empty place between -.5 and .5 (no tiles with center at 0). Converting X2
into factor, will fix it without any additional readjustment.
You might want to fix margins of the plot, thought.
How do I remove legend/grid without using theme_void()?
EDIT: Updated as you have posted an image. You do not have a legend, so you do not need to remove it. You want to remove the axis lines, ticks, text, title and maybe(?) the panel grid lines:
pic <- ggplot(data = art_dat, mapping = aes(x = x, y = y, group = path_id,
color = step_id)
) +
geom_path(
size = .9,
alpha = 1000, #transparency of the lines
show.legend = FALSE
) +
coord_equal() +
theme_light() +
scale_color_scico(palette = "berlin") +
theme(
axis.line = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
panel.grid.major = element_blank(), # optional - remove gridlines
panel.grid.minor = element_blank() # optional - remove gridlines
)
How can I suppress the vertical gridlines in a ggplot2 plot?
Try using
scale_x_continuous(breaks = NULL)
This would remove all the vertical gridlines as well as x-axis tickmark labels.
scale y axis on a polar plot in ggplot
I think this is a bit of a bug, or at least a missing feature (equivalent behaviour in Cartesian co-ordinates could be prevented by setting hard limits via ylim
in coord_cartesian
, which is not available in coord_polar
). There is no outer axis line in coord_polar
, and a grid line seems to be used in its place, without respecting axis.line
theme elements.
The only workaround I can find is somewhat "hacky", in that you can pass vectorized colours to the grid lines:
foo %>%
ggplot() +
geom_point(aes(x = theta, y = r)) +
coord_polar(clip = "off") +
scale_y_continuous(limits = c(0, 90), expand = c(0, 0), breaks = 90) +
scale_x_continuous(limits = c(0, 360), expand = c(0, 0),
breaks = c(0, 90, 180, 270)) +
theme(panel.grid.minor = element_blank(),
panel.grid.major.y = element_line(colour = c("red", NA)))
Related Topics
Installing R 3.5.0 with --Enable-R-Shlib
Plot Causes "Error: Incorrect Number of Dimensions"
Ggplot2: Is There a Fix for Jagged, Poor-Quality Text Produced by Geom_Text()
How to Get Factor Matrices in R
Number Formatting Axis Labels in Ggplot2
How to Create a Pivot Table in R with Multiple (3+) Variables
Calculating Standard Deviation of Each Row
How to Remove an Element in ... (Dot-Dot-Dot) and Pass It On
How to Get a Warning on "Shiny App Will Not Work If the Same Output Is Used Twice"
Link Selectinput with Sliderinput in Shiny
Create an Expression from a Function for Data.Table to Eval
Find the Index Position of the First Non-Na Value in an R Vector
Collapsing/Hiding Figures in R Markdown
Does Converting Character Columns to Factors Save Memory