How to set limits for axes in ggplot2 R plots?

I plot the following: library(ggplot2) carrots <- data.frame(length = rnorm(500000, 10000, 10000)) cukes <- data.frame(length = rnorm(50000, 10000, 20000)) carrots$veg <- 'carrot' cukes$veg...

ggplot2 legend to bottom and horizontal

How can I move a ggplot2 legend to the bottom of the plot and turn it horizontally? Sample code: library(reshape2) # for melt df <- melt(outer(1:4, 1:4), varnames = c("X1", "X2")) p1 <- ggplot(df,...

ggplot2 plot area margins?

Is there an easy way to increase the space between the plot title and plot area below it (i.e., the box with the data). Similarly, I'd prefer to have some space between the axis title and axis...

How to change legend title in ggplot

I have the following plot like below. It was created with this command: library(ggplot2) df <- data.frame(cond = factor(rep(c("A", "B"), each = 200)), rating = c(rnorm(200),...

Save plots made in a shiny app

I'm trying to figure out how to use downloadButton to save a plot with shiny. The example in the package demonstrates downloadButton/downloadHandler to save a .csv. I'm going to make a...

Label points in geom_point

The data I'm playing with comes from the internet source listed below nba <- read.csv("http://datasets.flowingdata.com/ppg2008.csv", sep=",") What I want to do, is create a 2D points graph...

How to deal with "data of class uneval" error from ggplot2?

While trying to overlay a new line to a existing ggplot I am getting the following error: Error: ggplot2 doesn't know how to deal with data of class uneval The first part of my code works fine. ...

How to make geom_text plot within the canvas's bounds

Using geom_text to label outlying points of scatter plot. By definition, these points tend to be close to the canvas edges: there is usually at least one word that overlaps the canvas edge,...

How to increase the size of points in legend of ggplot2?

I have thousands of points in one figure and set the "size = 1". However the point size in the legend is reduced too. How to increase the point size in the legend? For example. num <-...

Changing fonts in ggplot2

Once upon a time, I changed my ggplot2 font using using windowsFonts(Times=windowsFont("TT Times New Roman")) to change it. Now I can't get it off of this. In trying to set family="" in ggplot2...

ggplot2 legend items in a single horizontal row

This may seem like a stupid question, but I am a little confused. It seems that the code I wrote and tested last week has now suddenly decided to change the output even though nothing in the code...

How to plot coordinates on tmap output?

So far, I have managed to visually present data for different socio-economic factors at a district level in Pakistan with the help of the tmap package to create the following...

factoextra package: How can I plot my clusters using variable axes and not PCA component axes?

library(cluster) km.res <- kmeans(my_data, 4, nstart = 25) # Visualize library("factoextra") fviz_cluster(km.res, data = my_data, frame.type = "convex")+ theme_minimal() I would like to change...

Remove or hide zeroline on R ggplot2/factoextra plots

I am using this factoextra package in R to do Correspondent Analysis. When I print out the result plot, I can't find the option to hide the x and y zeroline. I know that the theme setting is...

How to reorder factor levels in a tidy way?

Hi I usually use some code like the following to reorder bars in ggplot or other types of plots. Normal plot (unordered) library(tidyverse) iris.tr <-iris %>% group_by(Species) %>% mutate(mSW =...

Ellipses for selected individuals - Factoextra plots

In order to show specific features from the results of my PCA (with FactomineR), I am trying to manipulate the plot of individuals and the biplot with the factoextra package. I want to draw...

How to obtain the matrix from the ordered dissimilarity image generated in fviz_dist?

I'm trying to obtain the matrix (Ordered dissimilarity matrix) from the ggplot that is generated with the function fviz_dist from factoextra package. From my original data I generated a distance...

Adding labels to Cluster

I'm new to R and am attempting to cluster some data based on industry. I have learned that K-means cannot handle factors and categorical data. I have removed the factor called 'Industry' -- 67...

Why and when "Using size for a discrete variable is not advised"?

I made a scattershot with ggplot2 and I mapped a binary variable to point size. The result was satisfactory but I got the warning "Using size for a discrete variable is not advised". I understand...

How to add a table to a ggplot?

I am trying to combine (in a single chart) a regular ggplot chart with a table obtained with flextable. Consider the following example: library(tidyverse) library(patchwork) mydf <- tibble(a =...

Insert new matrix in the R scatterplot

I would like to insert new coordinates in my scatterplot, from another matrix. I am using the fviz_cluster function to generate the graph for the clusters. I would like to insert the coordinates...

Exporting Kriged Values from R

Does anyone have any suggestions on how to export the values from your kriged data in R. I have them exported as a raster, but I need the actual cell values. The data that I'm working with are...

fun.y and stat_summary stopped working in ggplot

I used to run this code all the time to get the sum of 'n' at the top of my bar chart. Now I get the follow errors: Ignoring unknown parameters: fun.y No summary function supplied, defaulting to...

extracting multiple raster pixel values with shapefile and looping it with a list of radiuses

the problem i am trying to solve is that i want to extract the value of pixels of multiple rasters using a shapefile containing multiple point locations , for each point i would like to extract...

geom_smooth() with median instead of mean

I am building a plot with ggplot. I have data where y is mostly independent of X, but I randomly have a few extreme values of Y at low values of X. Like this: set.seed(1) X <- rnorm(500, mean=5) y...

point pattern analysis in Spatstat

I am having some trouble setting up my data for some point pattern analysis. What I want to do: conduct a point pattern analysis on NYC arrest data and see if there exists a spatial dependence...

Clustering plot. Add the cluster number: Function fviz_cluster (factoextra)

I have the following R code: library(factoextra) kms<-kmeans(df,18,nstart=100) fviz_cluster(kms, data = df, alpha=0.2,shape=19,geom = "point") It outputs the following picture: Is possible...

How to create a clickable histogram in Shiny?

I want to create a clickable histogram in shiny but I don't know if it is possible. Some months ago I saw a clickable volcano plot which gives you a table of what you click. Source:...

Is it possible to combine a ggplot legend and table

I was wondering if anyone knows a way to combine a table and ggplot legend so that the legend appears as a column in the table as shown in the image. Sorry if this has been asked before but I...