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

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?