ggplot: put axis text inside plotmove axis labels ggplotRotating and spacing axis labels in ggplot2Plot two graphs in same plot in RDoes ggplot's vjust of axis.text depend on angle?Numbered point labels plus a legend in a scatterplotSet y axis label position ggplot2Editing the text of a mathematical annotationHow to center ggplot plot titleggplot2: y axis labels left-justified inside plot areaRemoving axis labelling for one geom when multiple geoms are presentAdjusting Axis Label Position using ggplotly()

How do lasers measure short distances (<1cm) when electronics are too slow for time-of-flight to work?

one-liner vs script

'Cheddar goes "good" with burgers?' Can "go" be seen as a verb of the senses?

Had there been instances of national states banning harmful imports before the mid-19th C Opium Wars?

How to discipline overeager engineer

What is /dev/null and why can't I use hx on it?

What is the fastest way to move in Borderlands 3?

How can I remove rest of file from string for all files?

How to make "acts of patience" exciting?

Would it be easier to colonise a living world or a dead world?

Why do transition from one electronic shell to another shell always produce massless photon?

What if you can't publish in very high impact journal or top conference during your PhD?

Can I bring alcohol to Dubai?

Is the text of all UK treaties and laws public?

Translation Golf XLVIII — We're sorry to see you go

What do you call the fallacy of thinking that some action A will guarantee some outcome B, when in reality B depends on multiple other conditions?

Can I perform Umrah while on a Saudi Arabian visit e-visa

Can something have more sugar per 100g than the percentage of sugar that's in it?

Why did a young George Washington sign a document admitting to assassinating a French military officer?

Why would they pick a gamma distribution here?

Why are engines with carburetors hard to start in cold weather?

What ways are there to bypass spell resistance?

Canceling a color specification

What determines the top speed in ice skating?



ggplot: put axis text inside plot


move axis labels ggplotRotating and spacing axis labels in ggplot2Plot two graphs in same plot in RDoes ggplot's vjust of axis.text depend on angle?Numbered point labels plus a legend in a scatterplotSet y axis label position ggplot2Editing the text of a mathematical annotationHow to center ggplot plot titleggplot2: y axis labels left-justified inside plot areaRemoving axis labelling for one geom when multiple geoms are presentAdjusting Axis Label Position using ggplotly()






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









2















I want to put labels inside the plot area.



Here's an example plot:



library(ggplot2)

set.seed(123)
random_word <- function() paste(sample(letters, 10, replace = T), collapse='')
dat <- data.frame(x = replicate(4, random_word()),
y = runif(5*4, 0, 100))

ggplot(dat, aes(x = x, y = y)) +
geom_point() +
coord_flip() +
theme_minimal()


enter image description here



I know I can use geom_text to hack my way to the result I want:



ggplot(dat, aes(x = x, y = y)) +
geom_point() +
geom_text(data = dat[1:4,],
aes(label=x),
y = 1,
hjust=0, vjust=-1 ) +
coord_flip() +
theme_minimal() +
theme(axis.text.y = element_blank())


enter image description here



Comments on this question [ move axis labels ggplot ] suggest that margin is the non hacky way to do this in current ggplot, but it doesn't seem to move the axis text inside the plot area.



# doesn't do the trick
ggplot(dat, aes(x = x, y = y)) +
geom_point() +
coord_flip() +
theme_minimal() +
theme(axis.title.y = element_text(margin = margin(l = 50)))


Is there some elegant way to get this sort of output by setting theme() parameters?



my sessionInfo() is:



> sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.3

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] ggthemes_4.1.0 forcats_0.4.0 stringr_1.4.0 dplyr_0.8.0.1 purrr_0.3.1 readr_1.3.1
[7] tidyr_0.8.3 tibble_2.0.1 ggplot2_3.1.0 tidyverse_1.2.1









share|improve this question
























  • First of all, you want to move the axis.text.y so when you test that comment and it doesn't work, actually you are not even changing the right element, but that's not the main thing. margin() is obviously changing the margins. Labels are still getting printed in the area of between axis line and plot border so margin won't work for bringing labels inside the plot. Unless there's an option like what we have for plotting at the top/bottom/etc. (e.g. scale_x_discrete(position = "inside") ), which I am not aware of, I guess your best bet is your hacky solution.

    – M--
    Mar 28 at 22:20


















2















I want to put labels inside the plot area.



Here's an example plot:



library(ggplot2)

set.seed(123)
random_word <- function() paste(sample(letters, 10, replace = T), collapse='')
dat <- data.frame(x = replicate(4, random_word()),
y = runif(5*4, 0, 100))

ggplot(dat, aes(x = x, y = y)) +
geom_point() +
coord_flip() +
theme_minimal()


enter image description here



I know I can use geom_text to hack my way to the result I want:



ggplot(dat, aes(x = x, y = y)) +
geom_point() +
geom_text(data = dat[1:4,],
aes(label=x),
y = 1,
hjust=0, vjust=-1 ) +
coord_flip() +
theme_minimal() +
theme(axis.text.y = element_blank())


enter image description here



Comments on this question [ move axis labels ggplot ] suggest that margin is the non hacky way to do this in current ggplot, but it doesn't seem to move the axis text inside the plot area.



# doesn't do the trick
ggplot(dat, aes(x = x, y = y)) +
geom_point() +
coord_flip() +
theme_minimal() +
theme(axis.title.y = element_text(margin = margin(l = 50)))


Is there some elegant way to get this sort of output by setting theme() parameters?



my sessionInfo() is:



> sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.3

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] ggthemes_4.1.0 forcats_0.4.0 stringr_1.4.0 dplyr_0.8.0.1 purrr_0.3.1 readr_1.3.1
[7] tidyr_0.8.3 tibble_2.0.1 ggplot2_3.1.0 tidyverse_1.2.1









share|improve this question
























  • First of all, you want to move the axis.text.y so when you test that comment and it doesn't work, actually you are not even changing the right element, but that's not the main thing. margin() is obviously changing the margins. Labels are still getting printed in the area of between axis line and plot border so margin won't work for bringing labels inside the plot. Unless there's an option like what we have for plotting at the top/bottom/etc. (e.g. scale_x_discrete(position = "inside") ), which I am not aware of, I guess your best bet is your hacky solution.

    – M--
    Mar 28 at 22:20














2












2








2


1






I want to put labels inside the plot area.



Here's an example plot:



library(ggplot2)

set.seed(123)
random_word <- function() paste(sample(letters, 10, replace = T), collapse='')
dat <- data.frame(x = replicate(4, random_word()),
y = runif(5*4, 0, 100))

ggplot(dat, aes(x = x, y = y)) +
geom_point() +
coord_flip() +
theme_minimal()


enter image description here



I know I can use geom_text to hack my way to the result I want:



ggplot(dat, aes(x = x, y = y)) +
geom_point() +
geom_text(data = dat[1:4,],
aes(label=x),
y = 1,
hjust=0, vjust=-1 ) +
coord_flip() +
theme_minimal() +
theme(axis.text.y = element_blank())


enter image description here



Comments on this question [ move axis labels ggplot ] suggest that margin is the non hacky way to do this in current ggplot, but it doesn't seem to move the axis text inside the plot area.



# doesn't do the trick
ggplot(dat, aes(x = x, y = y)) +
geom_point() +
coord_flip() +
theme_minimal() +
theme(axis.title.y = element_text(margin = margin(l = 50)))


Is there some elegant way to get this sort of output by setting theme() parameters?



my sessionInfo() is:



> sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.3

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] ggthemes_4.1.0 forcats_0.4.0 stringr_1.4.0 dplyr_0.8.0.1 purrr_0.3.1 readr_1.3.1
[7] tidyr_0.8.3 tibble_2.0.1 ggplot2_3.1.0 tidyverse_1.2.1









share|improve this question














I want to put labels inside the plot area.



Here's an example plot:



library(ggplot2)

set.seed(123)
random_word <- function() paste(sample(letters, 10, replace = T), collapse='')
dat <- data.frame(x = replicate(4, random_word()),
y = runif(5*4, 0, 100))

ggplot(dat, aes(x = x, y = y)) +
geom_point() +
coord_flip() +
theme_minimal()


enter image description here



I know I can use geom_text to hack my way to the result I want:



ggplot(dat, aes(x = x, y = y)) +
geom_point() +
geom_text(data = dat[1:4,],
aes(label=x),
y = 1,
hjust=0, vjust=-1 ) +
coord_flip() +
theme_minimal() +
theme(axis.text.y = element_blank())


enter image description here



Comments on this question [ move axis labels ggplot ] suggest that margin is the non hacky way to do this in current ggplot, but it doesn't seem to move the axis text inside the plot area.



# doesn't do the trick
ggplot(dat, aes(x = x, y = y)) +
geom_point() +
coord_flip() +
theme_minimal() +
theme(axis.title.y = element_text(margin = margin(l = 50)))


Is there some elegant way to get this sort of output by setting theme() parameters?



my sessionInfo() is:



> sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.3

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] ggthemes_4.1.0 forcats_0.4.0 stringr_1.4.0 dplyr_0.8.0.1 purrr_0.3.1 readr_1.3.1
[7] tidyr_0.8.3 tibble_2.0.1 ggplot2_3.1.0 tidyverse_1.2.1






r ggplot2






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 28 at 21:05









arvi1000arvi1000

6,50222 silver badges38 bronze badges




6,50222 silver badges38 bronze badges















  • First of all, you want to move the axis.text.y so when you test that comment and it doesn't work, actually you are not even changing the right element, but that's not the main thing. margin() is obviously changing the margins. Labels are still getting printed in the area of between axis line and plot border so margin won't work for bringing labels inside the plot. Unless there's an option like what we have for plotting at the top/bottom/etc. (e.g. scale_x_discrete(position = "inside") ), which I am not aware of, I guess your best bet is your hacky solution.

    – M--
    Mar 28 at 22:20


















  • First of all, you want to move the axis.text.y so when you test that comment and it doesn't work, actually you are not even changing the right element, but that's not the main thing. margin() is obviously changing the margins. Labels are still getting printed in the area of between axis line and plot border so margin won't work for bringing labels inside the plot. Unless there's an option like what we have for plotting at the top/bottom/etc. (e.g. scale_x_discrete(position = "inside") ), which I am not aware of, I guess your best bet is your hacky solution.

    – M--
    Mar 28 at 22:20

















First of all, you want to move the axis.text.y so when you test that comment and it doesn't work, actually you are not even changing the right element, but that's not the main thing. margin() is obviously changing the margins. Labels are still getting printed in the area of between axis line and plot border so margin won't work for bringing labels inside the plot. Unless there's an option like what we have for plotting at the top/bottom/etc. (e.g. scale_x_discrete(position = "inside") ), which I am not aware of, I guess your best bet is your hacky solution.

– M--
Mar 28 at 22:20






First of all, you want to move the axis.text.y so when you test that comment and it doesn't work, actually you are not even changing the right element, but that's not the main thing. margin() is obviously changing the margins. Labels are still getting printed in the area of between axis line and plot border so margin won't work for bringing labels inside the plot. Unless there's an option like what we have for plotting at the top/bottom/etc. (e.g. scale_x_discrete(position = "inside") ), which I am not aware of, I guess your best bet is your hacky solution.

– M--
Mar 28 at 22:20













0






active

oldest

votes













Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406829%2fggplot-put-axis-text-inside-plot%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406829%2fggplot-put-axis-text-inside-plot%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript