(seiten)relative Größen für tikzDevice-Grafiken

Antwort erstellen


Diese Frage dient dazu, das automatisierte Versenden von Formularen durch Spam-Bots zu verhindern.
Smilies
:D :) :( :o :shock: :? 8) :lol: :-x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen:

BBCode ist eingeschaltet
[img] ist eingeschaltet
[flash] ist ausgeschaltet
[url] ist eingeschaltet
Smilies sind eingeschaltet

Die letzten Beiträge des Themas

Ich habe die Datenschutzerklärung gelesen und bin damit einverstanden.

   

Wenn du eine Datei oder mehrere Dateien anhängen möchtest, gib die Details unten ein.

Ansicht erweitern Die letzten Beiträge des Themas: (seiten)relative Größen für tikzDevice-Grafiken

von MoonKid » Fr 30. Okt 2015, 09:34

Hab es jetzt mal so gelöst.

Das R-Script
#!/usr/bin/R -f
## tikzDevice.R

# load the library
library(tikzDevice)

# first histogram
tikz('t-h1.tex')
hist(sample(-29:29,166,rep=TRUE))

# second histogram
tikz('t-h2.tex')
hist(rnorm(1000, 250, 1.4))
dev.off()
Der tex-code
%% tikzDevice.tex
\documentclass{scrartcl}
\usepackage{xltxtra}
\defaultfontfeatures{Mapping=tex-text}
\usepackage{graphicx}
\usepackage{polyglossia}
\setdefaultlanguage[spelling=new]{german}
\usepackage{tikz}

\begin{document}
\section{Histogramm}

\resizebox{0.45\textwidth}{!}{%
    \input{t-h1.tex}}
\hfil
\resizebox{0.45\textwidth}{!}{%
    \input{t-h2.tex}}
\end{document}

von Gast » Fr 30. Okt 2015, 07:19

Natürlich kannst Du Deine TikZ-Graphiken mit resizebox und Freunden skalieren. (Google einfach "scla etikz image" und Du findest Correctly scaling a tikzpicture, How to scale a tikzpicture including texts?, Specifying the width and height of a tikzpicture und Scale tikz figure to a percentage of \textwidth).

Allerdings würde ich Dir dringend empfehlen, bei tikzDevice gleich die richtige Größe zu bestellen. Da R bestimmte Vorgaben für den Rand usw. hat, ist es so, dass sich eine 4in-x-4in- von einer hochgerechneten 2in-x-2in-Version einer Graphik sehr wohl unterscheidet. Außerdem wird durch Hochrechnen häufig die Schriftgröße geändert, manchmal in sehr ungünstige Gefilde.

(seiten)relative Größen für tikzDevice-Grafiken

von MoonKid » Do 29. Okt 2015, 21:38

Bin nicht sicher, ob das hier eine tikzDevice-spezifische Frage ist, oder ob sich das mit tikz-eigenen Mitteln lösen lässt.

Das ist das R-file...
library(tikzDevice)
tikz('t-h.tex')
hist(sample(-29:29,166,rep=TRUE))

hist(rnorm(1000, 250, 1.4))
dev.off()
das ich mit R -f t-h.R auf der Shell ausführe. Die daraus generierte t-h.tex habe ich der Lesbarkeit halber ans Ende dieses Postings gestellt.

Diese binde ich in mein eigenes tex-file ein.
%% t.tex
\documentclass{scrartcl}
\usepackage{xltxtra}
\defaultfontfeatures{Mapping=tex-text}
\usepackage{graphicx}
\usepackage{polyglossia}
\setdefaultlanguage[spelling=new]{german}
\usepackage{tikz}

\begin{document}
\section{Histogramm}
\input{t-h.tex}
\end{document}
Problem ist nun die Größe der "Grafik". Sie ist zu groß. ;)
Ich möchte sie gerne realtiv (am besten zur Seitengröße und/oder Textbreite/-höhe) festlegen. Der tikz()-Aufruf in R hat zwar die Paramter width und heigth, meint damit aber absolute Werte in inch.

Wie geht man das an? Welche Komponenten (R, tikzDevice, tikz, tex selbst, ...?) muss ich anfassen dafür?

Beispielsweise möchte ich, das beide Grafiken zusammen auf eine Seite passen.
Eine andere (bessere) Variante wäre auch, das beide Grafiken nebeneinander stehen sollen (jede ca. 45% der Textbreite breit). Vermutlich müsste ich dann zwei separate R-files daraus machen.

Die generierte t-h.tex
% Created by tikzDevice version 0.8.1 on 2015-10-29 21:23:18
% !TEX encoding = UTF-8 Unicode
\begin{tikzpicture}[x=1pt,y=1pt]
\definecolor{fillColor}{RGB}{255,255,255}
\path[use as bounding box,fill=fillColor,fill opacity=0.00] (0,0) rectangle (505.89,505.89);
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (505.89,505.89);
\definecolor{drawColor}{RGB}{0,0,0}

\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.20] at (264.94,477.15) {\bfseries Histogram of sample(-29:29, 166, rep = TRUE)};

\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (264.94, 15.60) {sample(-29:29, 166, rep = TRUE)};

\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 10.80,258.94) {Frequency};
\end{scope}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (505.89,505.89);
\definecolor{drawColor}{RGB}{0,0,0}

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 65.18, 61.20) -- (464.71, 61.20);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 65.18, 61.20) -- ( 65.18, 55.20);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (131.77, 61.20) -- (131.77, 55.20);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (198.36, 61.20) -- (198.36, 55.20);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (264.95, 61.20) -- (264.95, 55.20);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (331.53, 61.20) -- (331.53, 55.20);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (398.12, 61.20) -- (398.12, 55.20);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (464.71, 61.20) -- (464.71, 55.20);

\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 65.18, 39.60) {-30};

\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (131.77, 39.60) {-20};

\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (198.36, 39.60) {-10};

\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (264.95, 39.60) {0};

\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (331.53, 39.60) {10};

\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (398.12, 39.60) {20};

\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (464.71, 39.60) {30};

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.20, 75.85) -- ( 49.20,408.75);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.20, 75.85) -- ( 43.20, 75.85);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.20,159.07) -- ( 43.20,159.07);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.20,242.30) -- ( 43.20,242.30);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.20,325.53) -- ( 43.20,325.53);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.20,408.75) -- ( 43.20,408.75);

\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 34.80, 75.85) {0};

\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 34.80,159.07) {5};

\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 34.80,242.30) {10};

\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 34.80,325.53) {15};

\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 34.80,408.75) {20};
\end{scope}
\begin{scope}
\path[clip] ( 49.20, 61.20) rectangle (480.69,456.69);
\definecolor{drawColor}{RGB}{0,0,0}

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 65.18, 75.85) rectangle ( 98.48,258.94);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 98.48, 75.85) rectangle (131.77,308.88);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (131.77, 75.85) rectangle (165.06,242.30);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (165.06, 75.85) rectangle (198.36,392.11);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (198.36, 75.85) rectangle (231.65,242.30);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (231.65, 75.85) rectangle (264.95,358.82);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (264.95, 75.85) rectangle (298.24,358.82);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (298.24, 75.85) rectangle (331.53,275.59);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (331.53, 75.85) rectangle (364.83,442.04);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (364.83, 75.85) rectangle (398.12,192.36);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (398.12, 75.85) rectangle (431.41,325.53);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (431.41, 75.85) rectangle (464.71,275.59);
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}[x=1pt,y=1pt]
\definecolor{fillColor}{RGB}{255,255,255}
\path[use as bounding box,fill=fillColor,fill opacity=0.00] (0,0) rectangle (505.89,505.89);
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (505.89,505.89);
\definecolor{drawColor}{RGB}{0,0,0}

\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.20] at (264.95,477.15) {\bfseries Histogram of rnorm(1000, 250, 1.4)};

\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (264.95, 15.60) {rnorm(1000, 250, 1.4)};

\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 10.80,258.94) {Frequency};
\end{scope}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (505.89,505.89);
\definecolor{drawColor}{RGB}{0,0,0}

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (105.13, 61.20) -- (424.76, 61.20);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (105.13, 61.20) -- (105.13, 55.20);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (185.04, 61.20) -- (185.04, 55.20);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (264.95, 61.20) -- (264.95, 55.20);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (344.85, 61.20) -- (344.85, 55.20);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (424.76, 61.20) -- (424.76, 55.20);

\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (105.13, 39.60) {246};

\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (185.04, 39.60) {248};

\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (264.95, 39.60) {250};

\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (344.85, 39.60) {252};

\node[text=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at (424.76, 39.60) {254};

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.20, 75.85) -- ( 49.20,394.83);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.20, 75.85) -- ( 43.20, 75.85);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.20,139.64) -- ( 43.20,139.64);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.20,203.44) -- ( 43.20,203.44);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.20,267.24) -- ( 43.20,267.24);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.20,331.04) -- ( 43.20,331.04);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 49.20,394.83) -- ( 43.20,394.83);

\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 34.80, 75.85) {0};

\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 34.80,139.64) {50};

\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 34.80,203.44) {100};

\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 34.80,267.24) {150};

\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 34.80,331.04) {200};

\node[text=drawColor,rotate= 90.00,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 34.80,394.83) {250};
\end{scope}
\begin{scope}
\path[clip] ( 49.20, 61.20) rectangle (480.69,456.69);
\definecolor{drawColor}{RGB}{0,0,0}

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] ( 65.18, 75.85) rectangle (105.13, 78.40);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (105.13, 75.85) rectangle (145.09,100.09);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (145.09, 75.85) rectangle (185.04,144.75);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (185.04, 75.85) rectangle (224.99,265.96);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (224.99, 75.85) rectangle (264.95,396.11);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (264.95, 75.85) rectangle (304.90,442.04);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (304.90, 75.85) rectangle (344.85,291.48);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (344.85, 75.85) rectangle (384.80,147.30);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (384.80, 75.85) rectangle (424.76, 89.88);

\path[draw=drawColor,line width= 0.4pt,line join=round,line cap=round] (424.76, 75.85) rectangle (464.71, 78.40);
\end{scope}
\end{tikzpicture}

Nach oben