logo
down
shadow

Adjust hexbin legend breaks


Adjust hexbin legend breaks

By : user2953166
Date : November 20 2020, 01:01 AM
wish helps you In this example of a hexbin plot, the legend on the right has 10 levels/classes/breaks. Does anyone know how to change the number of levels? Say I want to change it to 5 or something. , Like this?
code :
gplot.hexbin(hb,colorcut=5)
library(ggplot2)
ggplot(df, aes(x,y))+
  geom_hex(aes(fill=cut(..value..,breaks=pretty(..value..,n=5))),bins=15)+
  scale_fill_manual("Count",values=grey((5:0)/6))


Share : facebook icon twitter icon
ggplot2: Legend overlapping the plot area - is it possible to manually adjust legend position?

ggplot2: Legend overlapping the plot area - is it possible to manually adjust legend position?


By : Kevin
Date : March 29 2020, 07:55 AM
I wish this help you In my environment, the legend does not overlap the plot area at all, but anyway what is overlapping is the background of the legend, so you can remove it by:
code :
ggplot(carrots,aes(y=Yield,x=Field,fill=Breed)) +
 geom_bar() +
 opts(legend.direction = "horizontal",
    legend.position = "top",
        legend.background = theme_blank()) + # this does hack
 labs(fill="")
Plot issues - legend bar scale, breaks, legend, decimals

Plot issues - legend bar scale, breaks, legend, decimals


By : promodh
Date : March 29 2020, 07:55 AM
like below fixes the issue You can avoid log scale (as some users said you) using classIntervals() function from classInt package.
Using levelplot() (in my opinion the result is better than raster::plot() function):
code :
# Normal breaks
break1 <- classIntervals(predictors[[12]][!is.na(predictors[[12]])], n = 50, style = "equal")

levelplot(predictors[[12]], col.regions=colorRampPalette(brewer.pal(9, 'Blues')), at=break1$brks, margin=FALSE,main =predic_legends[12])
# Using quantiles
break1 <- classIntervals(predictors[[12]][!is.na(predictors[[12]])], n = 50, style = "quantile")

levelplot(predictors[[12]], col.regions=colorRampPalette(brewer.pal(9, 'Blues')), at=break1$brks, margin=FALSE,main =predic_legends[12])
p <- levelplot(predictors[[12]], col.regions=colorRampPalette(brewer.pal(9, 'Blues')), at=break1$brks, margin=FALSE,main =predic_legends[12])
library(maptools)
library(rgeos)

data(wrld_simpl)
pts <- gCentroid(wrld_simpl, byid = T)
p + layer(sp.polygons(wrld_simpl)) + layer(sp.points(pts))
p + layer(sp.polygons(wrld_simpl,col='firebrick')) + layer(sp.points(pts,pch = 12,col='red'))
Changing the legend title breaks the legend color in ggplot2

Changing the legend title breaks the legend color in ggplot2


By : P Rasethe
Date : March 29 2020, 07:55 AM
it helps some times I'm trying to change the legend title on my ggplot. Here are two examples (partly from here); the first one is with the sf package, which is what I'm really using. The second one is without that package which seems to have the same problem.
code :
ggplot() + 
  geom_sf(aes(colour = pop, size=pop), data = cities) +
  scale_color_continuous(name = 'newname')
ggplot - how to adjust spacing between legend items and edit legend symbols

ggplot - how to adjust spacing between legend items and edit legend symbols


By : user2228807
Date : March 29 2020, 07:55 AM
hop of those help? For reducing the space between your legend keys, I think you were pointed already in the right direction. Have you tried also negative values like this?
code :
p <- p + theme(legend.spacing.y = unit(-1,"cm"))
library(grid)

# Transform to a grob tree
g <- ggplotGrob(p)

# Helpful to check the structure of the grob Tree
View(g$grobs)

# Edit the specific line from the legend key
g$grobs[[15]][["grobs"]][[1]][["grobs"]][[4]][["x0"]] <- unit(0.5, "npc")
g$grobs[[15]][["grobs"]][[1]][["grobs"]][[4]][["y0"]] <- unit(0.1, "npc")
g$grobs[[15]][["grobs"]][[1]][["grobs"]][[4]][["x1"]] <- unit(0.5, "npc")
g$grobs[[15]][["grobs"]][[1]][["grobs"]][[4]][["y1"]] <- unit(0.9, "npc")

# Draw the edited grob tree
grid.newpage(); grid.draw(g)
matrix of hexbin plots with common bin/legend breaks

matrix of hexbin plots with common bin/legend breaks


By : Landon Fabbricino
Date : March 29 2020, 07:55 AM
With these it helps hexbin objects are plotted using grid graphics so your par(mfrow=c(3,3)) does not do anything. Each graph is plotted on a separate page. To get the details of the plot options:
Related Posts Related Posts :
  • Using German characters (ü, ö, ä, etc.) in text analysis (R)
  • R JAGS: Dimension mismatch
  • R - How to create a function that accepts a code block as parameter?
  • How do I manually set geom_bar fill color in ggplot
  • How can I get my points to connect in a plot and show a trend with NA values in data?
  • Read SPecific lines of a CSV file in R-language
  • ggplot stacked bar plot from 2 separate data frames
  • auto.arima not parallelizing
  • Histogram of binned data frame in R
  • R rewriting stringmanipulations implemented in loop to the R-way
  • get first entries in rows of list?
  • Conditionally removing rows from a matrix in R
  • Using a loop to find P(-1.5<Y<1.5) for a range of sample sizes
  • R-Count and list the maximum count row by row
  • Include Iverson Bracket in R documentation
  • update a data frame and environment in R
  • How to write dynamic cumulative multiple in R
  • format time using as.POSIX in R
  • Change the class of multiple columns
  • Remove period and spaces within column headings nested in a list of data frames
  • R: error message --- package error: "functionName" not resolved from current namespace
  • labels with geom_text ggplot2
  • Passing mongodb ISODate in R
  • Importing "csv" file with multiple-character separator to R?
  • Change row names of a table obtained from a lm regression using xtable function
  • R language iterate over R object
  • How do you delete the header in a dataframe?
  • Re coding in R using complicated statement
  • accumulating functions and closures in R
  • How do you combine two columns into a new column in a dataframe made of two or more different csv files?
  • Twitter authentication fails
  • Summing Values of One Vector Conditional on Values of Another Vector
  • draw cube into 3D scatterplot in RGL
  • lme4 translate formula to code in 3-level model
  • How to draw single axis plot in R
  • Combine geom_tile() and facet_grid/facet_wrap and remove space between tiles (ggplot2)
  • Use snpStats with R version 3.0.1
  • Makefile gives strange error while compiling markdown file into .docx file
  • How to determine whether a points lies in an ellipse
  • Summarize data already grouped in r
  • Is the bigvis package for R not available for R version 3.0.1?
  • Operator overloading in R reference classes
  • How to enable user to switch between ggplot2 and gVis graphs in R Shiny?
  • Is there an easy way to separate categorical vs continuous variables into two dataset in R
  • Correct previous year by id within R
  • Installation of rdyncall package for R
  • ggplot2 plot that evaluates the percentage and mean of a third variable at intersecting points
  • Error Handling with Lapply
  • data.table - split multiple columns
  • How to compute the overall mean for several files in R?
  • R: Graph Plotting: Subscripts in the legend like LaTeX
  • Restructuring data in R
  • Distance of pointsfrom cluster centers after K means clustering
  • R incorrect value of date function
  • Package "Imports" not loading in R development package
  • r - run a user defined function several times by taking column elements as parameters
  • Create input$selection to subset data AND radiobuttons to choose plot type in Shiny
  • Generate crosstabulations from dataframe of categorical variables in survey
  • Restructure output of R summary function
  • New behavior in data.table? .N / something with `by` (calculate proportion)
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org